Skip to content

Commit 6dda40d

Browse files
Initial work on (scalar|return) type declarations
1 parent 29f31e5 commit 6dda40d

39 files changed

+430
-1225
lines changed

src/CodeCoverage.php

+90-310
Large diffs are not rendered by default.

src/Driver/Driver.php

+2-6
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,11 @@ interface Driver
3838

3939
/**
4040
* Start collection of code coverage information.
41-
*
42-
* @param bool $determineUnusedAndDead
4341
*/
44-
public function start($determineUnusedAndDead = true);
42+
public function start(bool $determineUnusedAndDead = true);
4543

4644
/**
4745
* Stop collection of code coverage information.
48-
*
49-
* @return array
5046
*/
51-
public function stop();
47+
public function stop(): array;
5248
}

src/Driver/PHPDBG.php

+9-23
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
final class PHPDBG implements Driver
2121
{
2222
/**
23-
* Constructor.
23+
* @throws RuntimeException
2424
*/
2525
public function __construct()
2626
{
@@ -39,39 +39,30 @@ public function __construct()
3939

4040
/**
4141
* Start collection of code coverage information.
42-
*
43-
* @param bool $determineUnusedAndDead
4442
*/
45-
public function start($determineUnusedAndDead = true)
43+
public function start(bool $determineUnusedAndDead = true): void
4644
{
47-
phpdbg_start_oplog();
45+
\phpdbg_start_oplog();
4846
}
4947

5048
/**
5149
* Stop collection of code coverage information.
52-
*
53-
* @return array
5450
*/
55-
public function stop()
51+
public function stop(): array
5652
{
5753
static $fetchedLines = [];
5854

59-
$dbgData = phpdbg_end_oplog();
55+
$dbgData = \phpdbg_end_oplog();
6056

6157
if ($fetchedLines == []) {
62-
$sourceLines = phpdbg_get_executable();
58+
$sourceLines = \phpdbg_get_executable();
6359
} else {
64-
$newFiles = \array_diff(
65-
\get_included_files(),
66-
\array_keys($fetchedLines)
67-
);
60+
$newFiles = \array_diff(\get_included_files(), \array_keys($fetchedLines));
6861

6962
$sourceLines = [];
7063

7164
if ($newFiles) {
72-
$sourceLines = phpdbg_get_executable(
73-
['files' => $newFiles]
74-
);
65+
$sourceLines = phpdbg_get_executable(['files' => $newFiles]);
7566
}
7667
}
7768

@@ -88,13 +79,8 @@ public function stop()
8879

8980
/**
9081
* Convert phpdbg based data into the format CodeCoverage expects
91-
*
92-
* @param array $sourceLines
93-
* @param array $dbgData
94-
*
95-
* @return array
9682
*/
97-
private function detectExecutedLines(array $sourceLines, array $dbgData)
83+
private function detectExecutedLines(array $sourceLines, array $dbgData): array
9884
{
9985
foreach ($dbgData as $file => $coveredLines) {
10086
foreach ($coveredLines as $lineNo => $numExecuted) {

src/Driver/Xdebug.php

+8-24
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
final class Xdebug implements Driver
2121
{
2222
/**
23-
* Cache the number of lines for each file
24-
*
2523
* @var array
2624
*/
2725
private $cacheNumLines = [];
@@ -42,10 +40,8 @@ public function __construct()
4240

4341
/**
4442
* Start collection of code coverage information.
45-
*
46-
* @param bool $determineUnusedAndDead
4743
*/
48-
public function start($determineUnusedAndDead = true)
44+
public function start(bool $determineUnusedAndDead = true): void
4945
{
5046
if ($determineUnusedAndDead) {
5147
\xdebug_start_code_coverage(XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE);
@@ -56,10 +52,8 @@ public function start($determineUnusedAndDead = true)
5652

5753
/**
5854
* Stop collection of code coverage information.
59-
*
60-
* @return array
6155
*/
62-
public function stop()
56+
public function stop(): array
6357
{
6458
$data = \xdebug_get_code_coverage();
6559

@@ -68,12 +62,7 @@ public function stop()
6862
return $this->cleanup($data);
6963
}
7064

71-
/**
72-
* @param array $data
73-
*
74-
* @return array
75-
*/
76-
private function cleanup(array $data)
65+
private function cleanup(array $data): array
7766
{
7867
foreach (\array_keys($data) as $file) {
7968
unset($data[$file][0]);
@@ -92,24 +81,19 @@ private function cleanup(array $data)
9281
return $data;
9382
}
9483

95-
/**
96-
* @param string $file
97-
*
98-
* @return int
99-
*/
100-
private function getNumberOfLinesInFile($file)
84+
private function getNumberOfLinesInFile(string $fileName): int
10185
{
102-
if (!isset($this->cacheNumLines[$file])) {
103-
$buffer = \file_get_contents($file);
86+
if (!isset($this->cacheNumLines[$fileName])) {
87+
$buffer = \file_get_contents($fileName);
10488
$lines = \substr_count($buffer, "\n");
10589

10690
if (\substr($buffer, -1) !== "\n") {
10791
$lines++;
10892
}
10993

110-
$this->cacheNumLines[$file] = $lines;
94+
$this->cacheNumLines[$fileName] = $lines;
11195
}
11296

113-
return $this->cacheNumLines[$file];
97+
return $this->cacheNumLines[$fileName];
11498
}
11599
}

src/Exception/InvalidArgumentException.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ final class InvalidArgumentException extends \InvalidArgumentException implement
1919
*
2020
* @return InvalidArgumentException
2121
*/
22-
public static function create($argument, $type, $value = null)
22+
public static function create($argument, $type, $value = null): self
2323
{
2424
$stack = \debug_backtrace(0);
2525

src/Exception/UnintentionallyCoveredCodeException.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,15 @@ public function __construct(array $unintentionallyCoveredUnits)
3333
/**
3434
* @return array
3535
*/
36-
public function getUnintentionallyCoveredUnits()
36+
public function getUnintentionallyCoveredUnits(): array
3737
{
3838
return $this->unintentionallyCoveredUnits;
3939
}
4040

4141
/**
4242
* @return string
4343
*/
44-
private function toString()
44+
private function toString(): string
4545
{
4646
$message = '';
4747

src/Filter.php

+15-39
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,8 @@ final class Filter
2424

2525
/**
2626
* Adds a directory to the whitelist (recursively).
27-
*
28-
* @param string $directory
29-
* @param string $suffix
30-
* @param string $prefix
3127
*/
32-
public function addDirectoryToWhitelist($directory, $suffix = '.php', $prefix = '')
28+
public function addDirectoryToWhitelist(string $directory, string $suffix = '.php', string $prefix = ''): void
3329
{
3430
$facade = new \File_Iterator_Facade;
3531
$files = $facade->getFilesAsArray($directory, $suffix, $prefix);
@@ -41,20 +37,18 @@ public function addDirectoryToWhitelist($directory, $suffix = '.php', $prefix =
4137

4238
/**
4339
* Adds a file to the whitelist.
44-
*
45-
* @param string $filename
4640
*/
47-
public function addFileToWhitelist($filename)
41+
public function addFileToWhitelist(string $filename): void
4842
{
4943
$this->whitelistedFiles[\realpath($filename)] = true;
5044
}
5145

5246
/**
5347
* Adds files to the whitelist.
5448
*
55-
* @param array $files
49+
* @param string[] $files
5650
*/
57-
public function addFilesToWhitelist(array $files)
51+
public function addFilesToWhitelist(array $files): void
5852
{
5953
foreach ($files as $file) {
6054
$this->addFileToWhitelist($file);
@@ -63,12 +57,8 @@ public function addFilesToWhitelist(array $files)
6357

6458
/**
6559
* Removes a directory from the whitelist (recursively).
66-
*
67-
* @param string $directory
68-
* @param string $suffix
69-
* @param string $prefix
7060
*/
71-
public function removeDirectoryFromWhitelist($directory, $suffix = '.php', $prefix = '')
61+
public function removeDirectoryFromWhitelist(string $directory, string $suffix = '.php', string $prefix = ''): void
7262
{
7363
$facade = new \File_Iterator_Facade;
7464
$files = $facade->getFilesAsArray($directory, $suffix, $prefix);
@@ -80,10 +70,8 @@ public function removeDirectoryFromWhitelist($directory, $suffix = '.php', $pref
8070

8171
/**
8272
* Removes a file from the whitelist.
83-
*
84-
* @param string $filename
8573
*/
86-
public function removeFileFromWhitelist($filename)
74+
public function removeFileFromWhitelist(string $filename): void
8775
{
8876
$filename = \realpath($filename);
8977

@@ -92,14 +80,10 @@ public function removeFileFromWhitelist($filename)
9280

9381
/**
9482
* Checks whether a filename is a real filename.
95-
*
96-
* @param string $filename
97-
*
98-
* @return bool
9983
*/
100-
public function isFile($filename)
84+
public function isFile(string $filename): bool
10185
{
102-
if ($filename == '-' ||
86+
if ($filename === '-' ||
10387
\strpos($filename, 'vfs://') === 0 ||
10488
\strpos($filename, 'xdebug://debug-eval') !== false ||
10589
\strpos($filename, 'eval()\'d code') !== false ||
@@ -115,12 +99,8 @@ public function isFile($filename)
11599

116100
/**
117101
* Checks whether or not a file is filtered.
118-
*
119-
* @param string $filename
120-
*
121-
* @return bool
122102
*/
123-
public function isFiltered($filename)
103+
public function isFiltered(string $filename): bool
124104
{
125105
if (!$this->isFile($filename)) {
126106
return true;
@@ -134,39 +114,35 @@ public function isFiltered($filename)
134114
/**
135115
* Returns the list of whitelisted files.
136116
*
137-
* @return array
117+
* @return string[]
138118
*/
139-
public function getWhitelist()
119+
public function getWhitelist(): array
140120
{
141121
return \array_keys($this->whitelistedFiles);
142122
}
143123

144124
/**
145125
* Returns whether this filter has a whitelist.
146-
*
147-
* @return bool
148126
*/
149-
public function hasWhitelist()
127+
public function hasWhitelist(): bool
150128
{
151129
return !empty($this->whitelistedFiles);
152130
}
153131

154132
/**
155133
* Returns the whitelisted files.
156134
*
157-
* @return array
135+
* @return string[]
158136
*/
159-
public function getWhitelistedFiles()
137+
public function getWhitelistedFiles(): array
160138
{
161139
return $this->whitelistedFiles;
162140
}
163141

164142
/**
165143
* Sets the whitelisted files.
166-
*
167-
* @param array $whitelistedFiles
168144
*/
169-
public function setWhitelistedFiles($whitelistedFiles)
145+
public function setWhitelistedFiles(array $whitelistedFiles): void
170146
{
171147
$this->whitelistedFiles = $whitelistedFiles;
172148
}

0 commit comments

Comments
 (0)