Skip to content

Commit af0db30

Browse files
committed
Fix plugin wildcard for TableCallbacks.
1 parent b6c7834 commit af0db30

File tree

10 files changed

+20
-29
lines changed

10 files changed

+20
-29
lines changed

src/Annotator/CallbackAnnotatorTask/TableCallbackAnnotatorTask.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class TableCallbackAnnotatorTask extends AbstractCallbackAnnotatorTask implement
3737
*/
3838
public function shouldRun(string $path): bool {
3939
$className = pathinfo($path, PATHINFO_FILENAME);
40-
if ($className === 'Table' || substr($className, -5) !== 'Table') {
40+
if ($className === 'Table' || !str_ends_with($className, 'Table')) {
4141
return false;
4242
}
4343

src/Annotator/CommandAnnotator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class CommandAnnotator extends AbstractAnnotator {
1515
*/
1616
public function annotate(string $path): bool {
1717
$className = pathinfo($path, PATHINFO_FILENAME);
18-
if ($className === 'Command' || substr($className, -7) !== 'Command') {
18+
if ($className === 'Command' || !str_ends_with($className, 'Command')) {
1919
return false;
2020
}
2121

src/Annotator/ComponentAnnotator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class ComponentAnnotator extends AbstractAnnotator {
2424
*/
2525
public function annotate(string $path): bool {
2626
$name = pathinfo($path, PATHINFO_FILENAME);
27-
if (substr($name, -9) !== 'Component') {
27+
if (!str_ends_with($name, 'Component')) {
2828
return false;
2929
}
3030

src/Annotator/ControllerAnnotator.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class ControllerAnnotator extends AbstractAnnotator {
2929
*/
3030
public function annotate(string $path): bool {
3131
$className = pathinfo($path, PATHINFO_FILENAME);
32-
if (substr($className, -10) !== 'Controller') {
32+
if (!str_ends_with($className, 'Controller')) {
3333
return false;
3434
}
3535

@@ -119,7 +119,7 @@ protected function getComponentAnnotations(string $className, string $path): arr
119119

120120
$annotations = [];
121121
foreach ($map as $component => $className) {
122-
if (substr($className, 0, 5) === 'Cake\\') {
122+
if (str_starts_with($className, 'Cake\\')) {
123123
continue;
124124
}
125125

@@ -267,10 +267,10 @@ protected function getEntity(string $modelName, ?string $primaryModelName): stri
267267
* @return string|null
268268
*/
269269
protected function findModelClass(string $className, string $path): ?string {
270-
$plugin = $this->getConfig(static::CONFIG_PLUGIN) ? $this->getConfig(static::CONFIG_PLUGIN) . '.' : '';
270+
$plugin = $this->getConfig(static::CONFIG_PLUGIN);
271271
$prefix = $this->getPrefix($className, $path);
272272

273-
$fullClassName = App::className($plugin . $className, 'Controller' . $prefix);
273+
$fullClassName = App::className(($plugin ? $plugin . '.' : '') . $className, 'Controller' . $prefix);
274274
if (!$fullClassName) {
275275
return null;
276276
}

src/Annotator/HelperAnnotator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class HelperAnnotator extends AbstractAnnotator {
2020
*/
2121
public function annotate(string $path): bool {
2222
$name = pathinfo($path, PATHINFO_FILENAME);
23-
if (substr($name, -6) !== 'Helper') {
23+
if (!str_ends_with($name, 'Helper')) {
2424
return false;
2525
}
2626

src/Annotator/ModelAnnotator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class ModelAnnotator extends AbstractAnnotator {
3333
*/
3434
public function annotate(string $path): bool {
3535
$className = pathinfo($path, PATHINFO_FILENAME);
36-
if ($className === 'Table' || substr($className, -5) !== 'Table') {
36+
if ($className === 'Table' || !str_ends_with($className, 'Table')) {
3737
return false;
3838
}
3939

src/Annotator/Traits/DocBlockTrait.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,24 +129,24 @@ protected function stringifyValueNode(array $parts, PhpDocTagValueNode $valueNod
129129
* @param \PHP_CodeSniffer\Files\File $phpCsFile
130130
* @param int $docBlockStartIndex
131131
* @param int $docBlockEndIndex
132-
* @param string $needle
132+
* @param string $alias
133133
*
134134
* @return bool
135135
*/
136-
protected function hasInheritDoc(File $phpCsFile, int $docBlockStartIndex, int $docBlockEndIndex, string $needle = '@inheritDoc'): bool {
136+
protected function hasInheritDoc(File $phpCsFile, int $docBlockStartIndex, int $docBlockEndIndex, string $alias = '@inheritDoc'): bool {
137137
$tokens = $phpCsFile->getTokens();
138138

139139
for ($i = $docBlockStartIndex + 1; $i < $docBlockEndIndex; ++$i) {
140140
if (empty($tokens[$i]['content'])) {
141141
continue;
142142
}
143143
$content = $tokens[$i]['content'];
144-
$pos = stripos($content, $needle);
144+
$pos = stripos($content, $alias);
145145
if ($pos === false) {
146146
continue;
147147
}
148148

149-
if ($pos && str_starts_with($needle, '@') && substr($content, $pos - 1, $pos) === '{') {
149+
if ($pos && str_starts_with($alias, '@') && substr($content, $pos - 1, $pos) === '{') {
150150
return false;
151151
}
152152

src/Command/AnnotateCommand.php

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,6 @@ abstract class AnnotateCommand extends Command {
3030
],
3131
];
3232

33-
/**
34-
* @var array<string, \IdeHelper\Annotator\AbstractAnnotator>
35-
*/
36-
protected array $_instantiatedAnnotators = [];
37-
3833
/**
3934
* @return void
4035
*/
@@ -160,16 +155,12 @@ protected function getAnnotator(string $class): AbstractAnnotator {
160155
$class = $tasks[$class];
161156
}
162157

163-
if (!isset($this->_instantiatedAnnotators[$class])) {
164-
assert($this->args !== null, 'Args not set');
165-
166-
$options = $this->args->getOptions();
167-
$options['plugin'] = $this->plugin;
158+
assert($this->args !== null, 'Args not set');
168159

169-
$this->_instantiatedAnnotators[$class] = new $class($this->_io(), $options);
170-
}
160+
$options = $this->args->getOptions();
161+
$options['plugin'] = $this->plugin;
171162

172-
return $this->_instantiatedAnnotators[$class];
163+
return new $class($this->_io(), $options);
173164
}
174165

175166
/**

src/Filesystem/Folder.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ protected function _findRecursive(string $pattern, bool $sort = false): array {
291291
* @return bool true if windows path, false otherwise
292292
*/
293293
public static function isWindowsPath(string $path): bool {
294-
return preg_match('/^[A-Z]:\\\\/i', $path) || substr($path, 0, 2) === '\\\\';
294+
return preg_match('/^[A-Z]:\\\\/i', $path) || str_starts_with($path, '\\\\');
295295
}
296296

297297
/**
@@ -307,7 +307,7 @@ public static function isAbsolute(string $path): bool {
307307

308308
return $path[0] === '/' ||
309309
preg_match('/^[A-Z]:\\\\/i', $path) ||
310-
substr($path, 0, 2) === '\\\\' ||
310+
str_starts_with($path, '\\\\') ||
311311
static::isRegisteredStreamWrapper($path);
312312
}
313313

src/Generator/Task/FixtureTask.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ protected function parseFixtures(string $fixtureFolder, string $domain, ?string
7676

7777
$fixtures = [];
7878
foreach ($content[1] as $file) {
79-
if (substr($file, -11) !== 'Fixture.php') {
79+
if (!str_ends_with($file, 'Fixture.php')) {
8080
continue;
8181
}
8282
$fixture = substr($file, 0, -11);

0 commit comments

Comments
 (0)