Skip to content

Commit a88911b

Browse files
author
joseph
committed
fixing/supressing some PHPMD issues
1 parent 66fc6db commit a88911b

File tree

4 files changed

+28
-22
lines changed

4 files changed

+28
-22
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"jakub-onderka/php-console-highlighter": "^0.3.2",
2424
"edmondscommerce/php-parallel-lint": "~1.0.1",
2525
"phploc/phploc": "^4.0",
26-
"phpmd/phpmd": "^2.6",
26+
"phpmd/phpmd": "^2.8",
2727
"phpstan/phpstan": "^0.12",
2828
"squizlabs/php_codesniffer": "~3",
2929
"sllh/composer-versions-check": "^2.0",

composer.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Markdown/LinksChecker.php

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
use RegexIterator;
1313
use RuntimeException;
1414
use Throwable;
15-
1615
use function current;
1716
use function dirname;
1817
use function explode;
@@ -119,6 +118,7 @@ private static function getLinks(string $file): array
119118
{
120119
$links = [];
121120
$contents = (string)file_get_contents($file);
121+
$matches = null;
122122
if (
123123
preg_match_all(
124124
'/\[(.+?)\].*?\((.+?)\)/',
@@ -178,31 +178,32 @@ private static function checkLink(
178178
/**
179179
* @param string[] $link
180180
* @param string[] $errors
181+
* @SuppressWarnings(PHPMD.UndefinedVariable) - seems to not understand the static variable
181182
*/
182183
private static function validateHttpLink(array $link, array &$errors, int &$return): void
183184
{
185+
static $checked = [];
184186
list(, $anchor, $href) = $link;
185-
static $checked = [];
186-
$hashPos = (int)strpos($href, '#');
187+
$hashPos = (int)strpos($href, '#');
187188
if ($hashPos > 0) {
188189
$href = substr($href, 0, $hashPos);
189190
}
190191
if (isset($checked[$href])) {
191192
return;
192193
}
193194
$checked[$href] = true;
194-
//$start = microtime(true);
195-
//fwrite(STDERR, "\n".'Validating link: '.$href);
196-
$context = stream_context_create([
197-
'http' => [
198-
'method' => 'HEAD',
199-
'protocol_version' => 1.1,
200-
'header' => [
201-
'Connection: close',
195+
$context = stream_context_create(
196+
[
197+
'http' => [
198+
'method' => 'HEAD',
199+
'protocol_version' => 1.1,
200+
'header' => [
201+
'Connection: close',
202+
],
202203
],
203-
],
204-
]);
205-
$result = null;
204+
]
205+
);
206+
$result = null;
206207
try {
207208
$headers = get_headers($href, 0, $context);
208209
if ($headers === false) {

src/Psr4Validator.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ public function __construct(array $ignoreRegexPatterns, string $pathToProjectRoo
5757
}
5858

5959
/**
60+
* @return array[]
6061
* @throws Exception
6162
*
62-
* @return array[]
6363
*/
6464
public function main(): array
6565
{
@@ -91,17 +91,17 @@ public function main(): array
9191
*/
9292
private function loop(): void
9393
{
94-
foreach ($this->yieldPhpFilesToCheck() as list($absPathRoot, $namespaceRoot, $fileInfo)) {
94+
foreach ($this->yieldPhpFilesToCheck() as [$absPathRoot, $namespaceRoot, $fileInfo]) {
9595
$this->check($absPathRoot, $namespaceRoot, $fileInfo);
9696
}
9797
}
9898

9999
/**
100-
* @throws Exception
101-
*
102100
* @return Generator|mixed[]
103101
* @SuppressWarnings(PHPMD.StaticAccess)
104102
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
103+
* @throws Exception
104+
*
105105
*/
106106
private function yieldPhpFilesToCheck(): Generator
107107
{
@@ -157,6 +157,7 @@ private function addMissingPathError(string $path, string $namespaceRoot, string
157157

158158
/**
159159
* @return SplHeap|SplFileInfo[]
160+
* @SuppressWarnings(PHPMD.UndefinedVariable) - phpmd cant handle the anon class
160161
*/
161162
private function getDirectoryIterator(string $realPath): SplHeap
162163
{
@@ -178,8 +179,11 @@ public function __construct(RecursiveIteratorIterator $iterator)
178179
}
179180

180181
/**
181-
* @param mixed $item1
182-
* @param mixed $item2
182+
* @param SplFileInfo $item1
183+
* @param SplFileInfo $item2
184+
*
185+
* @return int
186+
*
183187
*/
184188
protected function compare($item1, $item2): int
185189
{
@@ -211,6 +215,7 @@ private function getActualNamespace(SplFileInfo $fileInfo): string
211215
if ($contents === false) {
212216
throw new RuntimeException('Failed getting file contents for ' . $fileInfo->getPathname());
213217
}
218+
$matches = null;
214219
\preg_match('%namespace\s+?([^;]+)%', $contents, $matches);
215220
if ([] === $matches) {
216221
$this->parseErrors[] = (string)$fileInfo->getRealPath();

0 commit comments

Comments
 (0)