Skip to content

Commit

Permalink
Fix plugin wildcard for TableCallbacks.
Browse files Browse the repository at this point in the history
  • Loading branch information
dereuromark committed Nov 25, 2024
1 parent b6c7834 commit af0db30
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class TableCallbackAnnotatorTask extends AbstractCallbackAnnotatorTask implement
*/
public function shouldRun(string $path): bool {
$className = pathinfo($path, PATHINFO_FILENAME);
if ($className === 'Table' || substr($className, -5) !== 'Table') {
if ($className === 'Table' || !str_ends_with($className, 'Table')) {
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Annotator/CommandAnnotator.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class CommandAnnotator extends AbstractAnnotator {
*/
public function annotate(string $path): bool {
$className = pathinfo($path, PATHINFO_FILENAME);
if ($className === 'Command' || substr($className, -7) !== 'Command') {
if ($className === 'Command' || !str_ends_with($className, 'Command')) {
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Annotator/ComponentAnnotator.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class ComponentAnnotator extends AbstractAnnotator {
*/
public function annotate(string $path): bool {
$name = pathinfo($path, PATHINFO_FILENAME);
if (substr($name, -9) !== 'Component') {
if (!str_ends_with($name, 'Component')) {
return false;
}

Expand Down
8 changes: 4 additions & 4 deletions src/Annotator/ControllerAnnotator.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class ControllerAnnotator extends AbstractAnnotator {
*/
public function annotate(string $path): bool {
$className = pathinfo($path, PATHINFO_FILENAME);
if (substr($className, -10) !== 'Controller') {
if (!str_ends_with($className, 'Controller')) {
return false;
}

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

$annotations = [];
foreach ($map as $component => $className) {
if (substr($className, 0, 5) === 'Cake\\') {
if (str_starts_with($className, 'Cake\\')) {
continue;
}

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

$fullClassName = App::className($plugin . $className, 'Controller' . $prefix);
$fullClassName = App::className(($plugin ? $plugin . '.' : '') . $className, 'Controller' . $prefix);
if (!$fullClassName) {
return null;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Annotator/HelperAnnotator.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class HelperAnnotator extends AbstractAnnotator {
*/
public function annotate(string $path): bool {
$name = pathinfo($path, PATHINFO_FILENAME);
if (substr($name, -6) !== 'Helper') {
if (!str_ends_with($name, 'Helper')) {
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Annotator/ModelAnnotator.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class ModelAnnotator extends AbstractAnnotator {
*/
public function annotate(string $path): bool {
$className = pathinfo($path, PATHINFO_FILENAME);
if ($className === 'Table' || substr($className, -5) !== 'Table') {
if ($className === 'Table' || !str_ends_with($className, 'Table')) {
return false;
}

Expand Down
8 changes: 4 additions & 4 deletions src/Annotator/Traits/DocBlockTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,24 +129,24 @@ protected function stringifyValueNode(array $parts, PhpDocTagValueNode $valueNod
* @param \PHP_CodeSniffer\Files\File $phpCsFile
* @param int $docBlockStartIndex
* @param int $docBlockEndIndex
* @param string $needle
* @param string $alias
*
* @return bool
*/
protected function hasInheritDoc(File $phpCsFile, int $docBlockStartIndex, int $docBlockEndIndex, string $needle = '@inheritDoc'): bool {
protected function hasInheritDoc(File $phpCsFile, int $docBlockStartIndex, int $docBlockEndIndex, string $alias = '@inheritDoc'): bool {
$tokens = $phpCsFile->getTokens();

for ($i = $docBlockStartIndex + 1; $i < $docBlockEndIndex; ++$i) {
if (empty($tokens[$i]['content'])) {
continue;
}
$content = $tokens[$i]['content'];
$pos = stripos($content, $needle);
$pos = stripos($content, $alias);
if ($pos === false) {
continue;
}

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

Expand Down
17 changes: 4 additions & 13 deletions src/Command/AnnotateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,6 @@ abstract class AnnotateCommand extends Command {
],
];

/**
* @var array<string, \IdeHelper\Annotator\AbstractAnnotator>
*/
protected array $_instantiatedAnnotators = [];

/**
* @return void
*/
Expand Down Expand Up @@ -160,16 +155,12 @@ protected function getAnnotator(string $class): AbstractAnnotator {
$class = $tasks[$class];
}

if (!isset($this->_instantiatedAnnotators[$class])) {
assert($this->args !== null, 'Args not set');

$options = $this->args->getOptions();
$options['plugin'] = $this->plugin;
assert($this->args !== null, 'Args not set');

$this->_instantiatedAnnotators[$class] = new $class($this->_io(), $options);
}
$options = $this->args->getOptions();
$options['plugin'] = $this->plugin;

return $this->_instantiatedAnnotators[$class];
return new $class($this->_io(), $options);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Filesystem/Folder.php
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ protected function _findRecursive(string $pattern, bool $sort = false): array {
* @return bool true if windows path, false otherwise
*/
public static function isWindowsPath(string $path): bool {
return preg_match('/^[A-Z]:\\\\/i', $path) || substr($path, 0, 2) === '\\\\';
return preg_match('/^[A-Z]:\\\\/i', $path) || str_starts_with($path, '\\\\');
}

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

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

Expand Down
2 changes: 1 addition & 1 deletion src/Generator/Task/FixtureTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ protected function parseFixtures(string $fixtureFolder, string $domain, ?string

$fixtures = [];
foreach ($content[1] as $file) {
if (substr($file, -11) !== 'Fixture.php') {
if (!str_ends_with($file, 'Fixture.php')) {
continue;
}
$fixture = substr($file, 0, -11);
Expand Down

0 comments on commit af0db30

Please sign in to comment.