This repository was archived by the owner on Feb 15, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathReturnCheck.php
More file actions
76 lines (69 loc) · 2.55 KB
/
Copy pathReturnCheck.php
File metadata and controls
76 lines (69 loc) · 2.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
namespace PhpDocBlockChecker\Check;
use PhpDocBlockChecker\FileInfo;
use PhpDocBlockChecker\Status\StatusType\Warning\ReturnMismatchWarning;
use PhpDocBlockChecker\Status\StatusType\Warning\ReturnMissingWarning;
class ReturnCheck extends Check
{
/**
* @param FileInfo $file
*/
public function check(FileInfo $file)
{
foreach ($file->getMethods() as $name => $method) {
if (!empty($method['return'])) {
if (empty($method['docblock']['return'])) {
$this->fileStatus->add(
new ReturnMissingWarning(
$file->getFileName(),
$name,
$method['line'],
$name
)
);
continue;
}
if (is_array($method['return'])) {
$docblockTypes = explode('|', $method['docblock']['return']);
sort($docblockTypes);
if ($method['return'] !== $docblockTypes) {
$this->fileStatus->add(
new ReturnMismatchWarning(
$file->getFileName(),
$name,
$method['line'],
$name,
implode('|', $method['return']),
$method['docblock']['return']
)
);
continue;
}
}
if (!is_array($method['return']) && $method['docblock']['return'] !== $method['return']) {
if ($method['return'] === 'array' && substr($method['docblock']['return'], -2) === '[]') {
// Do nothing because this is fine.
} else {
$this->fileStatus->add(
new ReturnMismatchWarning(
$file->getFileName(),
$name,
$method['line'],
$name,
$method['return'],
$method['docblock']['return']
)
);
}
}
}
}
}
/**
* @return bool
*/
public function enabled()
{
return !$this->config->isSkipSignatures();
}
}