Skip to content

Commit 5801510

Browse files
Initial work on data model for branch, path, and opcode coverage
1 parent bc058a1 commit 5801510

File tree

11 files changed

+592
-12
lines changed

11 files changed

+592
-12
lines changed

src/CodeCoverage/Data/Branch.php

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
/**
3+
* PHP_CodeCoverage
4+
*
5+
* Copyright (c) 2009-2014, Sebastian Bergmann <[email protected]>.
6+
* All rights reserved.
7+
*
8+
* Redistribution and use in source and binary forms, with or without
9+
* modification, are permitted provided that the following conditions
10+
* are met:
11+
*
12+
* * Redistributions of source code must retain the above copyright
13+
* notice, this list of conditions and the following disclaimer.
14+
*
15+
* * Redistributions in binary form must reproduce the above copyright
16+
* notice, this list of conditions and the following disclaimer in
17+
* the documentation and/or other materials provided with the
18+
* distribution.
19+
*
20+
* * Neither the name of Sebastian Bergmann nor the names of his
21+
* contributors may be used to endorse or promote products derived
22+
* from this software without specific prior written permission.
23+
*
24+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27+
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28+
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29+
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30+
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33+
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34+
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35+
* POSSIBILITY OF SUCH DAMAGE.
36+
*
37+
* @category PHP
38+
* @package CodeCoverage
39+
* @author Sebastian Bergmann <[email protected]>
40+
* @copyright 2009-2014 Sebastian Bergmann <[email protected]>
41+
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
42+
* @link http://github.com/sebastianbergmann/php-code-coverage
43+
* @since File available since Release 2.1.0
44+
*/
45+
46+
/**
47+
*
48+
*
49+
* @category PHP
50+
* @package CodeCoverage
51+
* @author Sebastian Bergmann <[email protected]>
52+
* @copyright 2009-2014 Sebastian Bergmann <[email protected]>
53+
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
54+
* @link http://github.com/sebastianbergmann/php-code-coverage
55+
* @since Class available since Release 2.1.0
56+
*/
57+
class PHP_CodeCoverage_Data_Branch
58+
{
59+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?php
2+
/**
3+
* PHP_CodeCoverage
4+
*
5+
* Copyright (c) 2009-2014, Sebastian Bergmann <[email protected]>.
6+
* All rights reserved.
7+
*
8+
* Redistribution and use in source and binary forms, with or without
9+
* modification, are permitted provided that the following conditions
10+
* are met:
11+
*
12+
* * Redistributions of source code must retain the above copyright
13+
* notice, this list of conditions and the following disclaimer.
14+
*
15+
* * Redistributions in binary form must reproduce the above copyright
16+
* notice, this list of conditions and the following disclaimer in
17+
* the documentation and/or other materials provided with the
18+
* distribution.
19+
*
20+
* * Neither the name of Sebastian Bergmann nor the names of his
21+
* contributors may be used to endorse or promote products derived
22+
* from this software without specific prior written permission.
23+
*
24+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27+
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28+
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29+
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30+
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33+
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34+
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35+
* POSSIBILITY OF SUCH DAMAGE.
36+
*
37+
* @category PHP
38+
* @package CodeCoverage
39+
* @author Sebastian Bergmann <[email protected]>
40+
* @copyright 2009-2014 Sebastian Bergmann <[email protected]>
41+
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
42+
* @link http://github.com/sebastianbergmann/php-code-coverage
43+
* @since File available since Release 2.1.0
44+
*/
45+
46+
/**
47+
*
48+
*
49+
* @category PHP
50+
* @package CodeCoverage
51+
* @author Sebastian Bergmann <[email protected]>
52+
* @copyright 2009-2014 Sebastian Bergmann <[email protected]>
53+
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
54+
* @link http://github.com/sebastianbergmann/php-code-coverage
55+
* @since Class available since Release 2.1.0
56+
*/
57+
class PHP_CodeCoverage_Data_BranchCollection
58+
{
59+
/**
60+
* @var PHP_CodeCoverage_Data_Branch[]
61+
*/
62+
private $branches = array();
63+
64+
/**
65+
* @param PHP_CodeCoverage_Data_Branch $branch
66+
*/
67+
public function addBranch(PHP_CodeCoverage_Data_Branch $branch)
68+
{
69+
$this->branches[] = $branch;
70+
}
71+
}

src/CodeCoverage/Data/File.php

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@
5656
*/
5757
class PHP_CodeCoverage_Data_File
5858
{
59+
/**
60+
* @var PHP_CodeCoverage_Data_FunctionCollection
61+
*/
62+
private $functions;
63+
5964
/**
6065
* @var PHP_CodeCoverage_Data_LineCollection
6166
*/
@@ -67,13 +72,15 @@ class PHP_CodeCoverage_Data_File
6772
private $path;
6873

6974
/**
70-
* @param string $path
71-
* @param PHP_CodeCoverage_Data_LineCollection $lines
75+
* @param string $path
76+
* @param PHP_CodeCoverage_Data_FunctionCollection $functions
77+
* @param PHP_CodeCoverage_Data_LineCollection $lines
7278
*/
73-
public function __construct($path, PHP_CodeCoverage_Data_LineCollection $lines)
79+
public function __construct($path, PHP_CodeCoverage_Data_FunctionCollection $functions, PHP_CodeCoverage_Data_LineCollection $lines)
7480
{
75-
$this->path = $path;
76-
$this->lines = $lines;
81+
$this->path = $path;
82+
$this->functions = $functions;
83+
$this->lines = $lines;
7784
}
7885

7986
/**

src/CodeCoverage/Data/FileCollection.php

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,17 +97,37 @@ public function merge(PHP_CodeCoverage_Data_FileCollection $other)
9797
*/
9898
private function createFile($path, array $lines)
9999
{
100-
$_lines = new PHP_CodeCoverage_Data_LineCollection;
101-
$this->files[$path] = new PHP_CodeCoverage_Data_File($path, $_lines);
100+
$_lines = new PHP_CodeCoverage_Data_LineCollection;
101+
$functions = new PHP_CodeCoverage_Data_FunctionCollection;
102+
// @todo Populate $functions
102103

103104
foreach ($lines as $lineNumber => $flag) {
104-
$_lines->addLine($lineNumber, new PHP_CodeCoverage_Data_Line($flag != -2, $flag == -2));
105+
$opcodes = new PHP_CodeCoverage_Data_OpcodeCollection;
106+
// @todo Populate $opcodes
107+
108+
$_lines->addLine(
109+
$lineNumber,
110+
new PHP_CodeCoverage_Data_Line(
111+
$opcodes,
112+
$flag != -2,
113+
$flag == -2
114+
)
115+
);
105116
}
106117

107118
for ($lineNumber = 1; $lineNumber <= PHP_CodeCoverage_Util::numberOfLinesInFile($path); $lineNumber++) {
108119
if (!isset($lines[$lineNumber])) {
109-
$_lines->addLine($lineNumber, new PHP_CodeCoverage_Data_Line(false, false));
120+
$_lines->addLine(
121+
$lineNumber,
122+
new PHP_CodeCoverage_Data_Line(
123+
new PHP_CodeCoverage_Data_OpcodeCollection,
124+
false,
125+
false
126+
)
127+
);
110128
}
111129
}
130+
131+
$this->files[$path] = new PHP_CodeCoverage_Data_File($path, $functions, $_lines);
112132
}
113133
}

src/CodeCoverage/Data/Function.php

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<?php
2+
/**
3+
* PHP_CodeCoverage
4+
*
5+
* Copyright (c) 2009-2014, Sebastian Bergmann <[email protected]>.
6+
* All rights reserved.
7+
*
8+
* Redistribution and use in source and binary forms, with or without
9+
* modification, are permitted provided that the following conditions
10+
* are met:
11+
*
12+
* * Redistributions of source code must retain the above copyright
13+
* notice, this list of conditions and the following disclaimer.
14+
*
15+
* * Redistributions in binary form must reproduce the above copyright
16+
* notice, this list of conditions and the following disclaimer in
17+
* the documentation and/or other materials provided with the
18+
* distribution.
19+
*
20+
* * Neither the name of Sebastian Bergmann nor the names of his
21+
* contributors may be used to endorse or promote products derived
22+
* from this software without specific prior written permission.
23+
*
24+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27+
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28+
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29+
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30+
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33+
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34+
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35+
* POSSIBILITY OF SUCH DAMAGE.
36+
*
37+
* @category PHP
38+
* @package CodeCoverage
39+
* @author Sebastian Bergmann <[email protected]>
40+
* @copyright 2009-2014 Sebastian Bergmann <[email protected]>
41+
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
42+
* @link http://github.com/sebastianbergmann/php-code-coverage
43+
* @since File available since Release 2.1.0
44+
*/
45+
46+
/**
47+
*
48+
*
49+
* @category PHP
50+
* @package CodeCoverage
51+
* @author Sebastian Bergmann <[email protected]>
52+
* @copyright 2009-2014 Sebastian Bergmann <[email protected]>
53+
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
54+
* @link http://github.com/sebastianbergmann/php-code-coverage
55+
* @since Class available since Release 2.1.0
56+
*/
57+
class PHP_CodeCoverage_Data_Function
58+
{
59+
/**
60+
* @var PHP_CodeCoverage_Data_OpcodeCollection
61+
*/
62+
private $opcodes;
63+
64+
/**
65+
* @var PHP_CodeCoverage_Data_BranchCollection
66+
*/
67+
private $branches;
68+
69+
/**
70+
* @var PHP_CodeCoverage_Data_PathCollection
71+
*/
72+
private $paths;
73+
74+
/**
75+
* @param PHP_CodeCoverage_Data_OpcodeCollection $opcodes
76+
* @param PHP_CodeCoverage_Data_BranchCollection $branches
77+
* @param PHP_CodeCoverage_Data_PathCollection $paths
78+
*/
79+
public function __construct(PHP_CodeCoverage_Data_OpcodeCollection $opcodes, PHP_CodeCoverage_Data_BranchCollection $branches, PHP_CodeCoverage_Data_PathCollection $paths)
80+
{
81+
$this->opcodes = $opcodes;
82+
$this->branches = $branches;
83+
$this->paths = $paths;
84+
}
85+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?php
2+
/**
3+
* PHP_CodeCoverage
4+
*
5+
* Copyright (c) 2009-2014, Sebastian Bergmann <[email protected]>.
6+
* All rights reserved.
7+
*
8+
* Redistribution and use in source and binary forms, with or without
9+
* modification, are permitted provided that the following conditions
10+
* are met:
11+
*
12+
* * Redistributions of source code must retain the above copyright
13+
* notice, this list of conditions and the following disclaimer.
14+
*
15+
* * Redistributions in binary form must reproduce the above copyright
16+
* notice, this list of conditions and the following disclaimer in
17+
* the documentation and/or other materials provided with the
18+
* distribution.
19+
*
20+
* * Neither the name of Sebastian Bergmann nor the names of his
21+
* contributors may be used to endorse or promote products derived
22+
* from this software without specific prior written permission.
23+
*
24+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27+
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28+
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29+
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30+
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33+
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34+
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35+
* POSSIBILITY OF SUCH DAMAGE.
36+
*
37+
* @category PHP
38+
* @package CodeCoverage
39+
* @author Sebastian Bergmann <[email protected]>
40+
* @copyright 2009-2014 Sebastian Bergmann <[email protected]>
41+
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
42+
* @link http://github.com/sebastianbergmann/php-code-coverage
43+
* @since File available since Release 2.1.0
44+
*/
45+
46+
/**
47+
*
48+
*
49+
* @category PHP
50+
* @package CodeCoverage
51+
* @author Sebastian Bergmann <[email protected]>
52+
* @copyright 2009-2014 Sebastian Bergmann <[email protected]>
53+
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
54+
* @link http://github.com/sebastianbergmann/php-code-coverage
55+
* @since Class available since Release 2.1.0
56+
*/
57+
class PHP_CodeCoverage_Data_FunctionCollection
58+
{
59+
/**
60+
* @var PHP_CodeCoverage_Data_Function[]
61+
*/
62+
private $functions = array();
63+
64+
/**
65+
* @param PHP_CodeCoverage_Data_Function $function
66+
*/
67+
public function addFunction(PHP_CodeCoverage_Data_Function $function)
68+
{
69+
$this->functions[] = $function;
70+
}
71+
}

src/CodeCoverage/Data/Line.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,18 @@ class PHP_CodeCoverage_Data_Line
7272
private $deadCode;
7373

7474
/**
75-
* @param boolean $executable
76-
* @param boolean $deadCode
75+
* @var PHP_CodeCoverage_Data_OpcodeCollection
7776
*/
78-
public function __construct($executable, $deadCode)
77+
private $opcodes;
78+
79+
/**
80+
* @param PHP_CodeCoverage_Data_OpcodeCollection $opcodes
81+
* @param boolean $executable
82+
* @param boolean $deadCode
83+
*/
84+
public function __construct(PHP_CodeCoverage_Data_OpcodeCollection $opcodes, $executable, $deadCode)
7985
{
86+
$this->opcodes = $opcodes;
8087
$this->executable = $executable;
8188
$this->deadCode = $deadCode;
8289
}

0 commit comments

Comments
 (0)