Skip to content

Commit 5b57986

Browse files
Resolve PHPCS issues
1 parent 541c9d7 commit 5b57986

File tree

6 files changed

+69
-27
lines changed

6 files changed

+69
-27
lines changed

setup/src/Magento/Setup/Module/Di/Code/Reader/ClassesScanner.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@
1010
use Magento\Framework\App\ObjectManager;
1111
use Magento\Framework\Exception\FileSystemException;
1212

13+
/**
14+
* Class ClassesScanner
15+
*
16+
* @package Magento\Setup\Module\Di\Code\Reader
17+
*/
1318
class ClassesScanner implements ClassesScannerInterface
1419
{
1520
/**
@@ -29,7 +34,8 @@ class ClassesScanner implements ClassesScannerInterface
2934

3035
/**
3136
* @param array $excludePatterns
32-
* @param string $generationDirectory
37+
* @param DirectoryList|null $directoryList
38+
* @throws FileSystemException
3339
*/
3440
public function __construct(array $excludePatterns = [], DirectoryList $directoryList = null)
3541
{
@@ -61,7 +67,7 @@ public function addExcludePatterns(array $excludePatterns)
6167
*/
6268
public function getList($path)
6369
{
64-
70+
// phpcs:ignore
6571
$realPath = realpath($path);
6672
$isGeneration = strpos($realPath, $this->generationDirectory) === 0;
6773

@@ -115,6 +121,8 @@ private function extract(\RecursiveIteratorIterator $recursiveIterator)
115121
}
116122

117123
/**
124+
* Include classes from file path
125+
*
118126
* @param array $classNames
119127
* @param string $fileItemPath
120128
* @return bool Whether the class is included or not
@@ -123,6 +131,7 @@ private function includeClasses(array $classNames, $fileItemPath)
123131
{
124132
foreach ($classNames as $className) {
125133
if (!class_exists($className)) {
134+
// phpcs:ignore
126135
require_once $fileItemPath;
127136
return true;
128137
}

setup/src/Magento/Setup/Module/Di/Code/Reader/FileClassScanner.php

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66

77
namespace Magento\Setup\Module\Di\Code\Reader;
88

9+
/**
10+
* Class FileClassScanner
11+
*
12+
* @package Magento\Setup\Module\Di\Code\Reader
13+
*/
914
class FileClassScanner
1015
{
1116
private const NAMESPACE_TOKENS = [
@@ -45,7 +50,9 @@ class FileClassScanner
4550
*/
4651
public function __construct($filename)
4752
{
53+
// phpcs:ignore
4854
$filename = realpath($filename);
55+
// phpcs:ignore
4956
if (!file_exists($filename) || !\is_file($filename)) {
5057
throw new InvalidFileException(
5158
sprintf(
@@ -64,12 +71,14 @@ public function __construct($filename)
6471
*/
6572
public function getFileContents()
6673
{
74+
// phpcs:ignore
6775
return file_get_contents($this->filename);
6876
}
6977

7078
/**
71-
* Extracts the fully qualified class name from a file. It only searches for the first match and stops looking
72-
* as soon as it enters the class definition itself.
79+
* Extracts the fully qualified class name from a file.
80+
*
81+
* It only searches for the first match and stops looking as soon as it enters the class definition itself.
7382
*
7483
* Warnings are suppressed for this method due to a micro-optimization that only really shows up when this logic
7584
* is called several millions of times, which can happen quite easily with even moderately sized codebases.
@@ -88,13 +97,14 @@ private function extract()
8897
$braceLevel = 0;
8998
$bracedNamespace = false;
9099

100+
// phpcs:ignore
91101
$this->tokens = token_get_all($this->getFileContents());
92102
foreach ($this->tokens as $index => $token) {
93103
$tokenIsArray = is_array($token);
94104
// Is either a literal brace or an interpolated brace with a variable
95105
if ($token === '{' || ($tokenIsArray && isset(self::ALLOWED_OPEN_BRACES_TOKENS[$token[0]]))) {
96106
$braceLevel++;
97-
} else if ($token === '}') {
107+
} elseif ($token === '}') {
98108
$braceLevel--;
99109
}
100110
// The namespace keyword was found in the last loop
@@ -107,8 +117,8 @@ private function extract()
107117
}
108118
$namespaceParts[] = $token[1];
109119

110-
// The class keyword was found in the last loop
111-
} else if ($triggerClass && $token[0] === T_STRING) {
120+
// The class keyword was found in the last loop
121+
} elseif ($triggerClass && $token[0] === T_STRING) {
112122
$triggerClass = false;
113123
$class = $token[1];
114124
}
@@ -151,7 +161,7 @@ private function isBracedNamespace($index)
151161
if (!is_array($this->tokens[$index])) {
152162
if ($this->tokens[$index] === ';') {
153163
return false;
154-
} else if ($this->tokens[$index] === '{') {
164+
} elseif ($this->tokens[$index] === '{') {
155165
return true;
156166
}
157167
continue;
@@ -165,8 +175,9 @@ private function isBracedNamespace($index)
165175
}
166176

167177
/**
168-
* Retrieves the first class found in a class file. The return value is in an array format so it retains the
169-
* same usage as the FileScanner.
178+
* Retrieves the first class found in a class file.
179+
*
180+
* The return value is in an array format so it retains the same usage as the FileScanner.
170181
*
171182
* @return array
172183
*/

setup/src/Magento/Setup/Module/Di/Code/Scanner/PhpScanner.php

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@
1111
use Magento\Setup\Module\Di\Compiler\Log\Log;
1212
use \Magento\Framework\Reflection\TypeProcessor;
1313

14+
/**
15+
* Class PhpScanner
16+
*
17+
* @package Magento\Setup\Module\Di\Code\Scanner
18+
*/
1419
class PhpScanner implements ScannerInterface
1520
{
1621
/**
@@ -167,6 +172,7 @@ protected function _fetchMissingExtensionAttributesClasses($reflectionClass, $fi
167172
*
168173
* @param array $files
169174
* @return array
175+
* @throws \ReflectionException
170176
*/
171177
public function collectEntities(array $files)
172178
{
@@ -183,29 +189,34 @@ public function collectEntities(array $files)
183189
}
184190

185191
/**
186-
* @param $tokenIterator int
187-
* @param $count int
188-
* @param $tokens array
192+
* Fetch namespaces from tokenized PHP file
193+
*
194+
* @param int $tokenIterator
195+
* @param int $count
196+
* @param array $tokens
189197
* @return string
190198
*/
191199
protected function _fetchNamespace($tokenIterator, $count, $tokens)
192200
{
193-
$namespace = '';
201+
$namespaceParts = [];
194202
for ($tokenOffset = $tokenIterator + 1; $tokenOffset < $count; ++$tokenOffset) {
195203
if ($tokens[$tokenOffset][0] === T_STRING) {
196-
$namespace .= "\\" . $tokens[$tokenOffset][1];
204+
$namespaceParts[] = "\\";
205+
$namespaceParts[] = $tokens[$tokenOffset][1];
197206
} elseif ($tokens[$tokenOffset] === '{' || $tokens[$tokenOffset] === ';') {
198207
break;
199208
}
200209
}
201-
return $namespace;
210+
return join('', $namespaceParts);
202211
}
203212

204213
/**
205-
* @param $namespace string
206-
* @param $tokenIterator int
207-
* @param $count int
208-
* @param $tokens array
214+
* Fetch class names from tokenized PHP file
215+
*
216+
* @param string $namespace
217+
* @param int $tokenIterator
218+
* @param int $count
219+
* @param array $tokens
209220
* @return array
210221
*/
211222
protected function _fetchClasses($namespace, $tokenIterator, $count, $tokens)
@@ -227,23 +238,24 @@ protected function _fetchClasses($namespace, $tokenIterator, $count, $tokens)
227238
*/
228239
protected function _getDeclaredClasses($file)
229240
{
230-
$classes = [];
231-
$namespace = '';
241+
$classes = [[]];
242+
$namespaceParts = [];
243+
// phpcs:ignore
232244
$tokens = token_get_all(file_get_contents($file));
233245
$count = count($tokens);
234246

235247
for ($tokenIterator = 0; $tokenIterator < $count; $tokenIterator++) {
236248
if ($tokens[$tokenIterator][0] == T_NAMESPACE) {
237-
$namespace .= $this->_fetchNamespace($tokenIterator, $count, $tokens);
249+
$namespaceParts[] = $this->_fetchNamespace($tokenIterator, $count, $tokens);
238250
}
239251

240252
if (($tokens[$tokenIterator][0] == T_CLASS || $tokens[$tokenIterator][0] == T_INTERFACE)
241253
&& $tokens[$tokenIterator - 1][0] != T_DOUBLE_COLON
242254
) {
243-
$classes = array_merge($classes, $this->_fetchClasses($namespace, $tokenIterator, $count, $tokens));
255+
$classes[] = $this->_fetchClasses(join('', $namespaceParts), $tokenIterator, $count, $tokens);
244256
}
245257
}
246-
return array_unique($classes);
258+
return array_unique(array_merge(...$classes));
247259
}
248260

249261
/**
@@ -260,7 +272,7 @@ private function shouldGenerateClass($missingClassName, $entityType, $file)
260272
if (class_exists($missingClassName)) {
261273
return false;
262274
}
263-
} catch (\RuntimeException $e) {
275+
} catch (\RuntimeException $e) { //phpcs:ignore
264276
}
265277
$sourceClassName = $this->getSourceClassName($missingClassName, $entityType);
266278
if (!class_exists($sourceClassName) && !interface_exists($sourceClassName)) {

setup/src/Magento/Setup/Module/Di/Compiler/Config/Chain/BackslashTrim.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@
88

99
use Magento\Setup\Module\Di\Compiler\Config\ModificationInterface;
1010

11+
/**
12+
* Class BackslashTrim
13+
*
14+
* @package Magento\Setup\Module\Di\Compiler\Config\Chain
15+
*/
1116
class BackslashTrim implements ModificationInterface
1217
{
1318
/**
@@ -71,6 +76,5 @@ private function resolveArguments(&$argument)
7176

7277
$this->resolveArguments($value);
7378
}
74-
return;
7579
}
7680
}

setup/src/Magento/Setup/Module/Di/Compiler/Config/Chain/PreferencesResolving.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@
88

99
use Magento\Setup\Module\Di\Compiler\Config\ModificationInterface;
1010

11+
/**
12+
* Class PreferencesResolving
13+
*
14+
* @package Magento\Setup\Module\Di\Compiler\Config\Chain
15+
*/
1116
class PreferencesResolving implements ModificationInterface
1217
{
1318
/**

setup/src/Magento/Setup/Module/Di/Compiler/Config/Reader.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
/**
1717
* Class Reader
18+
*
1819
* @package Magento\Setup\Module\Di\Compiler\Config
1920
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2021
*/

0 commit comments

Comments
 (0)