Conditions | 15 |
Paths | 156 |
Total Lines | 53 |
Code Lines | 32 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
75 | protected function isCorrupted(File $node) |
||
76 | { |
||
77 | $signatures = FileSignatures::getSignatures(); |
||
78 | |||
79 | try { |
||
80 | // get the first 1024 bytes |
||
81 | $handle = $node->fopen('r'); |
||
82 | $data = fread($handle, 1024); |
||
83 | fclose($handle); |
||
84 | |||
85 | $pathInfo = pathinfo($node->getPath()); |
||
86 | foreach ($signatures as $signature) { |
||
87 | $isFileCorrupted = true; |
||
88 | if (isset($pathInfo['extension']) && in_array(strtolower($pathInfo['extension']), $signature['extensions'])) { |
||
89 | // txt file extension has no signature, but is not corrupted |
||
90 | if (array_key_exists('exists', $signature['signature'])) { |
||
91 | if ($signature['signature']['exists'] === false) { |
||
92 | return new FileCorruptionResult(false); |
||
93 | } |
||
94 | } |
||
95 | // starting byte sequence |
||
96 | if (array_key_exists('starting', $signature['signature'])) { |
||
97 | foreach ($signature['signature']['starting']['bytes'] as $bytes) { |
||
98 | if (preg_match($bytes, strtolower(bin2hex(substr($data, $signature['signature']['starting']['offset'], strlen($bytes) / 2))))) { |
||
99 | $isFileCorrupted = false; |
||
100 | } |
||
101 | } |
||
102 | } |
||
103 | // trailing byte sequence |
||
104 | if (array_key_exists('trailing', $signature['signature'])) { |
||
105 | $trailingIsNotMatching = true; |
||
106 | foreach ($signature['signature']['trailing']['bytes'] as $bytes) { |
||
107 | $trailingOffset = strlen($data) - $signature['signature']['trailing']['offset'] - strlen($bytes) / 2; |
||
108 | if (preg_match($bytes, strtolower(bin2hex(substr($data, $trailingOffset, strlen($bytes) / 2))))) { |
||
109 | $trailingIsNotMatching = false; |
||
110 | } |
||
111 | } |
||
112 | $isFileCorrupted = $isFileCorrupted || $trailingIsNotMatching; |
||
113 | return new FileCorruptionResult($isFileCorrupted); |
||
114 | } |
||
115 | return new FileCorruptionResult($isFileCorrupted); |
||
116 | } |
||
117 | } |
||
118 | |||
119 | return new FileCorruptionResult(false); |
||
120 | } catch (\OCP\Files\NotPermittedException $exception) { |
||
121 | $this->logger->debug('isCorrupted: Not permitted.', array('app' => Application::APP_ID)); |
||
122 | |||
123 | return new FileCorruptionResult(false); |
||
124 | } catch (\OCP\Lock\LockedException $exception) { |
||
125 | $this->logger->debug('isCorrupted: File is locked.', array('app' => Application::APP_ID)); |
||
126 | |||
127 | return new FileCorruptionResult(false); |
||
128 | } |
||
131 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths