diff --git a/composer.json b/composer.json index 438ff04d..6ad33444 100644 --- a/composer.json +++ b/composer.json @@ -71,6 +71,9 @@ "stan": "@phpstan", "stan-baseline": "tools/phpstan --generate-baseline", "stan-setup": "phive install", + "rector-setup": "cp composer.json composer.backup && composer require --dev rector/rector:\"~2.3.1\" && mv composer.backup composer.json", + "rector-check": "vendor/bin/rector process --dry-run", + "rector-fix": "vendor/bin/rector process", "test": "phpunit", "test-coverage": "phpunit --coverage-clover=clover.xml" } diff --git a/rector.php b/rector.php new file mode 100644 index 00000000..1aaa408d --- /dev/null +++ b/rector.php @@ -0,0 +1,81 @@ +withPaths([ + __DIR__ . '/src', + __DIR__ . '/tests', + ]) + + ->withCache( + cacheClass: FileCacheStorage::class, + cacheDirectory: $cacheDir, + ) + + ->withPhpSets() + ->withAttributesSets() + + ->withSets([ + SetList::CODE_QUALITY, + SetList::CODING_STYLE, + SetList::DEAD_CODE, + SetList::EARLY_RETURN, + SetList::INSTANCEOF, + SetList::TYPE_DECLARATION, + ]) + + ->withSkip([ + __DIR__ . '/tests/comparisons', + __DIR__ . '/tests/test_app', + + ClassPropertyAssignToConstructorPromotionRector::class, + CatchExceptionNameMatchingTypeRector::class, + ClosureToArrowFunctionRector::class, + RemoveUselessReturnTagRector::class, + ReturnTypeFromStrictFluentReturnRector::class, + NewlineAfterStatementRector::class, + StringClassNameToClassConstantRector::class, + ReturnTypeFromStrictTypedCallRector::class, + ParamTypeByMethodCallTypeRector::class, + AddFunctionVoidReturnTypeWhereNoReturnRector::class, + StringableForToStringRector::class, + CompactToVariablesRector::class, + SplitDoubleAssignRector::class, + ChangeOrIfContinueToMultiContinueRector::class, + ExplicitBoolCompareRector::class, + NewlineBeforeNewAssignSetRector::class, + SimplifyEmptyCheckOnEmptyArrayRector::class, + DisallowedEmptyRuleFixerRector::class, + EncapsedStringsToSprintfRector::class, + + // these causes problems with the testsuite + UseClassKeywordForClassNameResolutionRector::class, + FunctionFirstClassCallableRector::class, + ]); diff --git a/src/BakePlugin.php b/src/BakePlugin.php index d4d225f6..e2ce6b65 100644 --- a/src/BakePlugin.php +++ b/src/BakePlugin.php @@ -34,15 +34,11 @@ class BakePlugin extends BasePlugin { /** * Plugin name. - * - * @var string|null */ protected ?string $name = 'Bake'; /** * Load routes or not - * - * @var bool */ protected bool $routesEnabled = false; @@ -95,13 +91,13 @@ protected function discoverCommands(CommandCollection $commands): CommandCollect $pluginPath = $plugin->getClassPath(); $found = $this->findInPath($namespace, $pluginPath); - if (count($found)) { + if ($found !== []) { $commands->addMany($found); } } $found = $this->findInPath(Configure::read('App.namespace'), APP); - if (count($found)) { + if ($found !== []) { $commands->addMany($found); } diff --git a/src/CodeGen/ClassBuilder.php b/src/CodeGen/ClassBuilder.php index 1cf858b1..68e481e6 100644 --- a/src/CodeGen/ClassBuilder.php +++ b/src/CodeGen/ClassBuilder.php @@ -18,9 +18,6 @@ class ClassBuilder { - /** - * @var \Bake\CodeGen\ParsedClass|null - */ protected ?ParsedClass $parsedClass; /** @@ -50,7 +47,7 @@ public function getImplements(array $generated = []): array */ public function getUserConstants(array $generated = []): array { - if ($this->parsedClass === null) { + if (!$this->parsedClass instanceof ParsedClass) { return []; } @@ -65,7 +62,7 @@ public function getUserConstants(array $generated = []): array */ public function getUserProperties(array $generated = []): array { - if ($this->parsedClass === null) { + if (!$this->parsedClass instanceof ParsedClass) { return []; } @@ -80,7 +77,7 @@ public function getUserProperties(array $generated = []): array */ public function getUserFunctions(array $generated = []): array { - if ($this->parsedClass === null) { + if (!$this->parsedClass instanceof ParsedClass) { return []; } diff --git a/src/CodeGen/CodeParser.php b/src/CodeGen/CodeParser.php index 9042f1bf..d3cc0e50 100644 --- a/src/CodeGen/CodeParser.php +++ b/src/CodeGen/CodeParser.php @@ -18,6 +18,8 @@ use PhpParser\Error; use PhpParser\Node; +use PhpParser\Node\Identifier; +use PhpParser\Node\Name; use PhpParser\Node\Stmt\Class_; use PhpParser\Node\Stmt\GroupUse; use PhpParser\Node\Stmt\Namespace_; @@ -41,24 +43,12 @@ class CodeParser extends NodeVisitorAbstract */ protected const INDENT = ' '; - /** - * @var \PhpParser\Parser - */ protected Parser $parser; - /** - * @var \PhpParser\NodeTraverser - */ protected NodeTraverser $traverser; - /** - * @var string - */ protected string $fileText = ''; - /** - * @var array - */ protected array $parsed = []; /** @@ -204,7 +194,7 @@ public function enterNode(Node $node) $methods[$name] = $this->getNodeCode($method); } - $implements = array_map(function ($name) { + $implements = array_map(function (Name $name): string { return (string)$name; }, $node->implements); @@ -237,9 +227,8 @@ protected function getNodeCode(NodeAbstract $node): string $startPos = $node->getStartFilePos(); $endPos = $node->getEndFilePos(); - $code .= static::INDENT . substr($this->fileText, $startPos, $endPos - $startPos + 1); - return $code; + return $code . static::INDENT . substr($this->fileText, $startPos, $endPos - $startPos + 1); } /** @@ -255,13 +244,9 @@ protected function normalizeUse(UseItem $use, ?string $prefix = null): array } $alias = $use->alias; - if (!$alias) { + if (!$alias instanceof Identifier) { $last = strrpos($name, '\\', -1); - if ($last !== false) { - $alias = substr($name, strrpos($name, '\\', -1) + 1); - } else { - $alias = $name; - } + $alias = $last !== false ? substr($name, strrpos($name, '\\', -1) + 1) : $name; } return [(string)$alias, $name]; diff --git a/src/CodeGen/ColumnTypeExtractor.php b/src/CodeGen/ColumnTypeExtractor.php index 9df1df08..074cd530 100644 --- a/src/CodeGen/ColumnTypeExtractor.php +++ b/src/CodeGen/ColumnTypeExtractor.php @@ -34,9 +34,6 @@ */ class ColumnTypeExtractor extends NodeVisitorAbstract { - /** - * @var \PhpParser\Parser - */ protected Parser $parser; /** @@ -44,9 +41,6 @@ class ColumnTypeExtractor extends NodeVisitorAbstract */ protected array $columnTypes = []; - /** - * @var bool - */ protected bool $inInitialize = false; /** @@ -80,7 +74,7 @@ public function extract(string $code): array $traverser = new NodeTraverser(); $traverser->addVisitor($this); $traverser->traverse($ast); - } catch (Exception $e) { + } catch (Exception) { // If parsing fails, return empty array return []; } @@ -135,39 +129,42 @@ public function leaveNode(Node $node) */ protected function processMethodCall(MethodCall $methodCall): void { - // Check if this is a setColumnType call - if ($methodCall->name instanceof Node\Identifier && $methodCall->name->name === 'setColumnType') { - // Check if it's called on getSchema() - if ( - $methodCall->var instanceof MethodCall && - $methodCall->var->name instanceof Node\Identifier && - $methodCall->var->name->name === 'getSchema' && - $methodCall->var->var instanceof Variable && - $methodCall->var->var->name === 'this' - ) { - // Extract the column name and type expression - if (count($methodCall->args) >= 2) { - $columnArgNode = $methodCall->args[0]; - $typeArgNode = $methodCall->args[1]; - if (!$columnArgNode instanceof Node\Arg || !$typeArgNode instanceof Node\Arg) { - return; - } - $columnArg = $columnArgNode->value; - $typeArg = $typeArgNode->value; - - // Get column name - $columnName = $this->getStringValue($columnArg); - if ($columnName === null) { - return; - } - - // Get the type expression as a string - $typeExpression = $this->getTypeExpression($typeArg); - if ($typeExpression !== null) { - $this->columnTypes[$columnName] = $typeExpression; - } - } - } + $isSetColumnTypeCall = $methodCall->name instanceof Node\Identifier + && $methodCall->name->name === 'setColumnType'; + $schemaCall = $methodCall->var; + $isSchemaMethodCall = $schemaCall instanceof MethodCall; + $hasEnoughArguments = count($methodCall->args) >= 2; + + if (!$isSetColumnTypeCall || !$isSchemaMethodCall || !$hasEnoughArguments) { + return; + } + + $isGetSchemaCall = $schemaCall->name instanceof Node\Identifier + && $schemaCall->name->name === 'getSchema'; + $isCalledOnThis = $schemaCall->var instanceof Variable + && $schemaCall->var->name === 'this'; + + if (!$isGetSchemaCall || !$isCalledOnThis) { + return; + } + + $columnArgNode = $methodCall->args[0]; + $typeArgNode = $methodCall->args[1]; + if (!$columnArgNode instanceof Node\Arg || !$typeArgNode instanceof Node\Arg) { + return; + } + + $columnArg = $columnArgNode->value; + $typeArg = $typeArgNode->value; + + $columnName = $this->getStringValue($columnArg); + if ($columnName === null) { + return; + } + + $typeExpression = $this->getTypeExpression($typeArg); + if ($typeExpression !== null) { + $this->columnTypes[$columnName] = $typeExpression; } } @@ -194,40 +191,50 @@ protected function getStringValue(Node $node): ?string */ protected function getTypeExpression(Node $node): ?string { - // Handle EnumType::from() calls - if ( - $node instanceof Node\Expr\StaticCall && - $node->class instanceof Node\Name && - $node->name instanceof Node\Identifier - ) { - $className = $node->class->toString(); - $methodName = $node->name->name; - - // Handle EnumType::from() calls - if ($className === 'EnumType' || str_ends_with($className, '\\EnumType')) { - if ($methodName === 'from' && count($node->args) > 0) { - // Extract the enum class name - $argNode = $node->args[0]; - if (!$argNode instanceof Node\Arg) { - return null; - } - $arg = $argNode->value; - if ($arg instanceof Node\Expr\ClassConstFetch) { - if ( - $arg->class instanceof Node\Name && - $arg->name instanceof Node\Identifier && - $arg->name->name === 'class' - ) { - $enumClass = $arg->class->toString(); - // Return the full EnumType::from() expression - return 'EnumType::from(' . $enumClass . '::class)'; - } - } - } + if ($node instanceof Node\Expr\StaticCall) { + $staticCall = $node; + $calledClass = $staticCall->class; + $calledMethod = $staticCall->name; + + $hasNamedClass = $calledClass instanceof Node\Name; + $hasIdentifierMethod = $calledMethod instanceof Node\Identifier; + if (!$hasNamedClass || !$hasIdentifierMethod) { + return null; + } + + $className = $calledClass->toString(); + $methodName = $calledMethod->name; + $isEnumTypeClass = $className === 'EnumType' || str_ends_with($className, '\\EnumType'); + $isFromMethod = $methodName === 'from'; + $hasArguments = $staticCall->args !== []; + if (!$isEnumTypeClass || !$isFromMethod || !$hasArguments) { + return null; + } + + $argNode = $staticCall->args[0]; + if (!$argNode instanceof Node\Arg) { + return null; } + + $arg = $argNode->value; + if (!$arg instanceof Node\Expr\ClassConstFetch) { + return null; + } + + $enumClassNode = $arg->class; + $constantName = $arg->name; + $hasNamedEnumClass = $enumClassNode instanceof Node\Name; + $isClassConstant = $constantName instanceof Node\Identifier + && $constantName->name === 'class'; + if (!$hasNamedEnumClass || !$isClassConstant) { + return null; + } + + $enumClass = $enumClassNode->toString(); + + return 'EnumType::from(' . $enumClass . '::class)'; } - // Handle simple string types if ($node instanceof Node\Scalar\String_) { return '"' . $node->value . '"'; } diff --git a/src/CodeGen/FileBuilder.php b/src/CodeGen/FileBuilder.php index 1aee4e15..ece3c8b1 100644 --- a/src/CodeGen/FileBuilder.php +++ b/src/CodeGen/FileBuilder.php @@ -20,24 +20,12 @@ class FileBuilder { - /** - * @var \Cake\Console\ConsoleIo - */ protected ConsoleIo $io; - /** - * @var string - */ protected string $namespace; - /** - * @var \Bake\CodeGen\ParsedFile|null - */ protected ?ParsedFile $parsedFile; - /** - * @var \Bake\CodeGen\ClassBuilder - */ protected ClassBuilder $classBuilder; /** @@ -47,7 +35,7 @@ class FileBuilder */ public function __construct(ConsoleIo $io, string $namespace, ?ParsedFile $parsedFile = null) { - if ($parsedFile && $parsedFile->namespace !== $namespace) { + if ($parsedFile instanceof ParsedFile && $parsedFile->namespace !== $namespace) { throw new ParseException(sprintf( 'Existing namespace `%s` does not match expected namespace `%s`, cannot update existing file', $parsedFile->namespace, diff --git a/src/CodeGen/ImportHelper.php b/src/CodeGen/ImportHelper.php index 3b786ffd..40308c90 100644 --- a/src/CodeGen/ImportHelper.php +++ b/src/CodeGen/ImportHelper.php @@ -32,11 +32,7 @@ public static function normalize(array $imports): array foreach ($imports as $alias => $class) { if (is_int($alias)) { $last = strrpos($class, '\\', -1); - if ($last !== false) { - $alias = substr($class, strrpos($class, '\\', -1) + 1); - } else { - $alias = $class; - } + $alias = $last !== false ? substr($class, strrpos($class, '\\', -1) + 1) : $class; } $normalized[$alias] = $class; @@ -58,7 +54,7 @@ public static function merge(array $existing, array $imports, ?ConsoleIo $io = n $existing = static::normalize($existing); foreach (static::normalize($imports) as $alias => $class) { if (isset($existing[$alias]) && $existing[$alias] !== $class) { - if ($io) { + if ($io instanceof ConsoleIo) { $io->warning(sprintf( 'Import `%s` conflicts with existing import, discarding.', $class, @@ -68,8 +64,8 @@ public static function merge(array $existing, array $imports, ?ConsoleIo $io = n } $existingAlias = array_search($class, $existing, true); - if ($existingAlias !== false && $existingAlias != $alias) { - if ($io) { + if ($existingAlias !== false && $existingAlias !== $alias) { + if ($io instanceof ConsoleIo) { $io->warning(sprintf( 'Import `%s` conflicts with existing import, discarding.', $class, diff --git a/src/CodeGen/ParsedClass.php b/src/CodeGen/ParsedClass.php index dcb9ba9d..28cad4de 100644 --- a/src/CodeGen/ParsedClass.php +++ b/src/CodeGen/ParsedClass.php @@ -21,9 +21,6 @@ */ class ParsedClass { - /** - * @var string - */ public string $name; /** diff --git a/src/CodeGen/ParsedFile.php b/src/CodeGen/ParsedFile.php index 2abed81f..185032bf 100644 --- a/src/CodeGen/ParsedFile.php +++ b/src/CodeGen/ParsedFile.php @@ -21,9 +21,6 @@ */ class ParsedFile { - /** - * @var string - */ public string $namespace; /** @@ -41,9 +38,6 @@ class ParsedFile */ public array $constImports; - /** - * @var \Bake\CodeGen\ParsedClass - */ public ParsedClass $class; /** diff --git a/src/Command/AllCommand.php b/src/Command/AllCommand.php index 8cccf7b4..cd0a5993 100644 --- a/src/Command/AllCommand.php +++ b/src/Command/AllCommand.php @@ -45,7 +45,7 @@ class AllCommand extends BakeCommand * @param \Cake\Console\ConsoleOptionParser $parser Option parser to update. * @return \Cake\Console\ConsoleOptionParser */ - public function buildOptionParser(ConsoleOptionParser $parser): ConsoleOptionParser + protected function buildOptionParser(ConsoleOptionParser $parser): ConsoleOptionParser { $parser = $this->_setCommonOptions($parser); diff --git a/src/Command/BakeCommand.php b/src/Command/BakeCommand.php index f5ade6a2..1c783b2e 100644 --- a/src/Command/BakeCommand.php +++ b/src/Command/BakeCommand.php @@ -44,8 +44,6 @@ abstract class BakeCommand extends Command /** * The pathFragment appended to the plugin/app path. - * - * @var string */ protected string $pathFragment; @@ -77,7 +75,7 @@ public function initialize(): void public static function defaultName(): string { $name = parent::defaultName(); - if (strpos($name, 'bake_') === 0) { + if (str_starts_with($name, 'bake_')) { $name = substr($name, 5); } @@ -119,7 +117,7 @@ protected function getPrefix(Arguments $args): string } $parts = explode('/', $prefix); - return implode('/', array_map([$this, '_camelize'], $parts)); + return implode('/', array_map($this->_camelize(...), $parts)); } /** @@ -214,7 +212,7 @@ protected function deleteEmptyFile(string $path, ConsoleIo $io): void */ protected function isValidColumnName(string $name): bool { - return (bool)preg_match('/^[a-zA-Z_][a-zA-Z0-9_]*$/', $name); + return (bool)preg_match('/^[a-zA-Z_]\w*$/', $name); } /** diff --git a/src/Command/BehaviorCommand.php b/src/Command/BehaviorCommand.php index 40968e9e..c4a06a33 100644 --- a/src/Command/BehaviorCommand.php +++ b/src/Command/BehaviorCommand.php @@ -23,8 +23,6 @@ class BehaviorCommand extends SimpleBakeCommand { /** * Task name used in path generation. - * - * @var string */ public string $pathFragment = 'Model/Behavior/'; diff --git a/src/Command/CellCommand.php b/src/Command/CellCommand.php index 657e738b..c0fb6dc5 100644 --- a/src/Command/CellCommand.php +++ b/src/Command/CellCommand.php @@ -28,8 +28,6 @@ class CellCommand extends SimpleBakeCommand { /** * Task name used in path generation. - * - * @var string */ public string $pathFragment = 'View/Cell/'; @@ -87,7 +85,7 @@ public function templateData(Arguments $arguments): array * @param \Cake\Console\ConsoleIo $io The console io * @return void */ - public function bake(string $name, Arguments $args, ConsoleIo $io): void + protected function bake(string $name, Arguments $args, ConsoleIo $io): void { $this->bakeTemplate($name, $args, $io); @@ -116,7 +114,7 @@ protected function bakeTemplate(string $name, Arguments $args, ConsoleIo $io): v * @param \Cake\Console\ConsoleOptionParser $parser Parser instance * @return \Cake\Console\ConsoleOptionParser */ - public function buildOptionParser(ConsoleOptionParser $parser): ConsoleOptionParser + protected function buildOptionParser(ConsoleOptionParser $parser): ConsoleOptionParser { $parser = parent::buildOptionParser($parser); $parser->addOption('prefix', [ diff --git a/src/Command/CommandCommand.php b/src/Command/CommandCommand.php index 54cc7ae5..8612f330 100644 --- a/src/Command/CommandCommand.php +++ b/src/Command/CommandCommand.php @@ -26,8 +26,6 @@ class CommandCommand extends SimpleBakeCommand { /** * Task name used in path generation. - * - * @var string */ public string $pathFragment = 'Command/'; diff --git a/src/Command/CommandHelperCommand.php b/src/Command/CommandHelperCommand.php index 542ac180..643ed758 100644 --- a/src/Command/CommandHelperCommand.php +++ b/src/Command/CommandHelperCommand.php @@ -23,8 +23,6 @@ class CommandHelperCommand extends SimpleBakeCommand { /** * Task name used in path generation. - * - * @var string */ public string $pathFragment = 'Command/Helper/'; diff --git a/src/Command/ComponentCommand.php b/src/Command/ComponentCommand.php index 3adace9b..af1bbe80 100644 --- a/src/Command/ComponentCommand.php +++ b/src/Command/ComponentCommand.php @@ -23,8 +23,6 @@ class ComponentCommand extends SimpleBakeCommand { /** * Task name used in path generation. - * - * @var string */ public string $pathFragment = 'Controller/Component/'; diff --git a/src/Command/ControllerAllCommand.php b/src/Command/ControllerAllCommand.php index 113e9006..43ffb3ca 100644 --- a/src/Command/ControllerAllCommand.php +++ b/src/Command/ControllerAllCommand.php @@ -30,9 +30,6 @@ class ControllerAllCommand extends BakeCommand { use LocatorAwareTrait; - /** - * @var \Bake\Command\ControllerCommand - */ protected ControllerCommand $controllerCommand; /** @@ -83,7 +80,7 @@ public function execute(Arguments $args, ConsoleIo $io): ?int * @param \Cake\Console\ConsoleOptionParser $parser The console option parser * @return \Cake\Console\ConsoleOptionParser */ - public function buildOptionParser(ConsoleOptionParser $parser): ConsoleOptionParser + protected function buildOptionParser(ConsoleOptionParser $parser): ConsoleOptionParser { $parser = $this->controllerCommand->buildOptionParser($parser); $parser diff --git a/src/Command/ControllerCommand.php b/src/Command/ControllerCommand.php index 82ca60d0..675a255e 100644 --- a/src/Command/ControllerCommand.php +++ b/src/Command/ControllerCommand.php @@ -31,8 +31,6 @@ class ControllerCommand extends BakeCommand { /** * Path fragment for generated code. - * - * @var string */ public string $pathFragment = 'Controller/'; @@ -229,10 +227,8 @@ public function getComponents(Arguments $args): array if ($args->getOption('components')) { $components = explode(',', (string)$args->getOption('components')); $components = array_values(array_filter(array_map('trim', $components))); - } else { - if (Plugin::isLoaded('Authorization')) { - $components[] = 'Authorization.Authorization'; - } + } elseif (Plugin::isLoaded('Authorization')) { + $components[] = 'Authorization.Authorization'; } return $components; @@ -261,7 +257,7 @@ public function getHelpers(Arguments $args): array * @param \Cake\Console\ConsoleOptionParser $parser The console option parser * @return \Cake\Console\ConsoleOptionParser */ - public function buildOptionParser(ConsoleOptionParser $parser): ConsoleOptionParser + protected function buildOptionParser(ConsoleOptionParser $parser): ConsoleOptionParser { $parser = $this->_setCommonOptions($parser); $parser->setDescription( diff --git a/src/Command/EntryCommand.php b/src/Command/EntryCommand.php index 7c2d1c7d..7f8490ad 100644 --- a/src/Command/EntryCommand.php +++ b/src/Command/EntryCommand.php @@ -32,15 +32,11 @@ class EntryCommand extends Command implements CommandCollectionAwareInterface { /** * The command collection to get help on. - * - * @var \Cake\Console\CommandCollection */ protected CommandCollection $commands; /** * The HelpCommand to get help. - * - * @var \Cake\Console\Command\HelpCommand */ protected HelpCommand $help; @@ -110,7 +106,7 @@ public function execute(Arguments $args, ConsoleIo $io): ?int if ($args->hasArgumentAt(0)) { $name = $args->getArgumentAt(0); $io->error( - "Could not find bake command named `$name`." + "Could not find bake command named `{$name}`." . ' Run `bake --help` to get a list of commands.', ); @@ -127,7 +123,7 @@ public function execute(Arguments $args, ConsoleIo $io): ?int * @param \Cake\Console\ConsoleOptionParser $parser The console option parser * @return \Cake\Console\ConsoleOptionParser */ - public function buildOptionParser(ConsoleOptionParser $parser): ConsoleOptionParser + protected function buildOptionParser(ConsoleOptionParser $parser): ConsoleOptionParser { $this->help = new HelpCommand(); $parser = $this->help->buildOptionParser($parser); @@ -139,12 +135,12 @@ public function buildOptionParser(ConsoleOptionParser $parser): ConsoleOptionPar ); $commands = []; foreach ($this->commands as $command => $class) { - if (substr($command, 0, 4) === 'bake') { + if (str_starts_with($command, 'bake')) { $parts = explode(' ', $command); // Remove `bake` array_shift($parts); - if (count($parts) === 0) { + if ($parts === []) { continue; } $commands[$command] = $class; diff --git a/src/Command/EnumCommand.php b/src/Command/EnumCommand.php index b1f02f03..5eee0d0e 100644 --- a/src/Command/EnumCommand.php +++ b/src/Command/EnumCommand.php @@ -30,8 +30,6 @@ class EnumCommand extends SimpleBakeCommand { /** * Task name used in path generation. - * - * @var string */ public string $pathFragment = 'Model/Enum/'; @@ -92,7 +90,7 @@ public function templateData(Arguments $arguments): array * @param \Cake\Console\ConsoleOptionParser $parser The option parser to update. * @return \Cake\Console\ConsoleOptionParser */ - public function buildOptionParser(ConsoleOptionParser $parser): ConsoleOptionParser + protected function buildOptionParser(ConsoleOptionParser $parser): ConsoleOptionParser { $parser = $this->_setCommonOptions($parser); @@ -141,7 +139,7 @@ protected function formatCases(array $cases): array foreach ($cases as $case => $value) { $case = Inflector::camelize(Inflector::underscore($case)); if (is_string($value)) { - $value = '\'' . $value . '\''; + $value = "'" . $value . "'"; } $formatted[] = 'case ' . $case . ' = ' . $value . ';'; } diff --git a/src/Command/FixtureAllCommand.php b/src/Command/FixtureAllCommand.php index 0b9b594d..241e7277 100644 --- a/src/Command/FixtureAllCommand.php +++ b/src/Command/FixtureAllCommand.php @@ -44,7 +44,7 @@ public static function defaultName(): string * @param \Cake\Console\ConsoleOptionParser $parser The parser to update * @return \Cake\Console\ConsoleOptionParser */ - public function buildOptionParser(ConsoleOptionParser $parser): ConsoleOptionParser + protected function buildOptionParser(ConsoleOptionParser $parser): ConsoleOptionParser { $parser = $this->_setCommonOptions($parser); diff --git a/src/Command/FixtureCommand.php b/src/Command/FixtureCommand.php index 5ccdec22..1ae33678 100644 --- a/src/Command/FixtureCommand.php +++ b/src/Command/FixtureCommand.php @@ -62,7 +62,7 @@ public function getPath(Arguments $args): string * @param \Cake\Console\ConsoleOptionParser $parser Option parser to update. * @return \Cake\Console\ConsoleOptionParser */ - public function buildOptionParser(ConsoleOptionParser $parser): ConsoleOptionParser + protected function buildOptionParser(ConsoleOptionParser $parser): ConsoleOptionParser { $parser = $this->_setCommonOptions($parser); @@ -163,7 +163,7 @@ protected function bake(string $model, string $useTable, Arguments $args, Consol try { $data = $this->readSchema($model, $useTable); - } catch (CakeException $e) { + } catch (CakeException) { $this->getTableLocator()->remove($model); $useTable = Inflector::underscore($model); $table = $useTable; @@ -288,19 +288,19 @@ protected function _generateSchema(TableSchemaInterface $table): string /** @var array $fieldData */ $fieldData = $table->getColumn($field); $properties = implode(', ', $this->_values($fieldData)); - $cols[] = " '$field' => [$properties],"; + $cols[] = " '{$field}' => [{$properties}],"; } foreach ($table->indexes() as $index) { /** @var array $fieldData */ $fieldData = $table->getIndex($index); $properties = implode(', ', $this->_values($fieldData)); - $indexes[] = " '$index' => [$properties],"; + $indexes[] = " '{$index}' => [{$properties}],"; } foreach ($table->constraints() as $index) { /** @var array $fieldData */ $fieldData = $table->getConstraint($index); $properties = implode(', ', $this->_values($fieldData)); - $constraints[] = " '$index' => [$properties],"; + $constraints[] = " '{$index}' => [{$properties}],"; } $options = $this->_values($table->getOptions()); @@ -318,7 +318,7 @@ protected function _generateSchema(TableSchemaInterface $table): string $content .= " '_options' => [\n" . implode(",\n", $options) . "\n ],\n"; } - return "[\n$content ]"; + return "[\n{$content} ]"; } /** @@ -339,11 +339,7 @@ protected function _values(array $values): array if ($val === 'NULL') { $val = 'null'; } - if (!is_numeric($key)) { - $vals[] = "'{$key}' => {$val}"; - } else { - $vals[] = "{$val}"; - } + $vals[] = is_numeric($key) ? "{$val}" : "'{$key}' => {$val}"; } } @@ -425,7 +421,7 @@ protected function _generateRecords(TableSchemaInterface $table, int $recordCoun $insert = Text::uuid(); break; } - if (str_starts_with($fieldInfo['type'], 'enum-')) { + if (str_starts_with((string)$fieldInfo['type'], 'enum-')) { $insert = null; if ($fieldInfo['default'] || $fieldInfo['null'] === false) { $dbType = TypeFactory::build($fieldInfo['type']); diff --git a/src/Command/FormCommand.php b/src/Command/FormCommand.php index af938259..95b680e8 100644 --- a/src/Command/FormCommand.php +++ b/src/Command/FormCommand.php @@ -23,8 +23,6 @@ class FormCommand extends SimpleBakeCommand { /** * Task name used in path generation. - * - * @var string */ public string $pathFragment = 'Form/'; diff --git a/src/Command/HelperCommand.php b/src/Command/HelperCommand.php index 41a74955..81c43f5f 100644 --- a/src/Command/HelperCommand.php +++ b/src/Command/HelperCommand.php @@ -23,8 +23,6 @@ class HelperCommand extends SimpleBakeCommand { /** * Task name used in path generation. - * - * @var string */ public string $pathFragment = 'View/Helper/'; diff --git a/src/Command/MailerCommand.php b/src/Command/MailerCommand.php index beba9875..6cd9d187 100644 --- a/src/Command/MailerCommand.php +++ b/src/Command/MailerCommand.php @@ -26,8 +26,6 @@ class MailerCommand extends SimpleBakeCommand { /** * Task name used in path generation. - * - * @var string */ public string $pathFragment = 'Mailer/'; @@ -63,7 +61,7 @@ public function template(): string * @param \Cake\Console\ConsoleIo $io The console io * @return void */ - public function bake(string $name, Arguments $args, ConsoleIo $io): void + protected function bake(string $name, Arguments $args, ConsoleIo $io): void { parent::bake($name, $args, $io); } diff --git a/src/Command/MiddlewareCommand.php b/src/Command/MiddlewareCommand.php index 9d376cd4..499c579b 100644 --- a/src/Command/MiddlewareCommand.php +++ b/src/Command/MiddlewareCommand.php @@ -23,8 +23,6 @@ class MiddlewareCommand extends SimpleBakeCommand { /** * Task name used in path generation. - * - * @var string */ public string $pathFragment = 'Middleware/'; diff --git a/src/Command/ModelAllCommand.php b/src/Command/ModelAllCommand.php index a65f696c..2bbae1a7 100644 --- a/src/Command/ModelAllCommand.php +++ b/src/Command/ModelAllCommand.php @@ -30,9 +30,6 @@ class ModelAllCommand extends BakeCommand { use LocatorAwareTrait; - /** - * @var \Bake\Command\ModelCommand - */ protected ModelCommand $modelCommand; /** @@ -60,7 +57,7 @@ public function initialize(): void * @param \Cake\Console\ConsoleOptionParser $parser The parser to configure * @return \Cake\Console\ConsoleOptionParser */ - public function buildOptionParser(ConsoleOptionParser $parser): ConsoleOptionParser + protected function buildOptionParser(ConsoleOptionParser $parser): ConsoleOptionParser { $parser = $this->modelCommand->buildOptionParser($parser); $parser diff --git a/src/Command/ModelCommand.php b/src/Command/ModelCommand.php index 33ec59f5..26e06102 100644 --- a/src/Command/ModelCommand.php +++ b/src/Command/ModelCommand.php @@ -18,6 +18,7 @@ use Bake\CodeGen\ColumnTypeExtractor; use Bake\CodeGen\FileBuilder; +use Bake\CodeGen\ParsedFile; use Bake\Utility\Model\EnumParser; use Bake\Utility\TableScanner; use Cake\Console\Arguments; @@ -45,8 +46,6 @@ class ModelCommand extends BakeCommand { /** * path to Model directory - * - * @var string */ public string $pathFragment = 'Model/'; @@ -54,8 +53,6 @@ class ModelCommand extends BakeCommand * Table prefix * * Can be replaced in application subclasses if necessary - * - * @var string */ public string $tablePrefix = ''; @@ -257,9 +254,7 @@ public function getAssociations(Table $table, Arguments $args, ConsoleIo $io): a $associations = $this->findHasMany($table, $associations); $associations = $this->findBelongsToMany($table, $associations); - $associations = $this->ensureAliasUniqueness($associations); - - return $associations; + return $this->ensureAliasUniqueness($associations); } /** @@ -275,7 +270,7 @@ public function getAssociations(Table $table, Arguments $args, ConsoleIo $io): a */ public function applyAssociations(Table $model, array $associations): void { - if (get_class($model) !== Table::class) { + if ($model::class !== Table::class) { return; } @@ -315,7 +310,7 @@ public function getAssociationInfo(Table $table): array foreach ($table->associations() as $association) { /** @var \Cake\ORM\Association $association */ - $tableClass = get_class($association->getTarget()); + $tableClass = $association->getTarget()::class; if ($tableClass === Table::class) { $namespace = $appNamespace; @@ -325,7 +320,7 @@ public function getAssociationInfo(Table $table): array $namespace = $plugin; } - $namespace = str_replace('/', '\\', trim($namespace, '\\')); + $namespace = str_replace('/', '\\', trim((string)$namespace, '\\')); $tableClass = $namespace . '\Model\Table\\' . $className . 'Table'; } @@ -374,10 +369,10 @@ public function findBelongsTo(Table $model, array $associations, ?Arguments $arg $tables = $this->listAll(); // Check if association model could not be instantiated as a subclass but a generic Table instance instead if ( - get_class($associationTable) === Table::class && + $associationTable::class === Table::class && !in_array(Inflector::tableize($tmpModelName), $tables, true) ) { - $allowAliasRelations = $args && $args->getOption('skip-relation-check'); + $allowAliasRelations = $args instanceof Arguments && $args->getOption('skip-relation-check'); $found = $this->findTableReferencedBy($schema, $fieldName); if ($found) { $className = ($this->plugin ? $this->plugin . '.' : '') . Inflector::camelize($found); @@ -433,8 +428,8 @@ public function findTableReferencedBy(TableSchemaInterface $schema, string $keyF continue; } $length = $this->tablePrefix ? mb_strlen($this->tablePrefix) : 0; - if ($length > 0 && mb_substr($constraintInfo['references'][0], 0, $length) === $this->tablePrefix) { - return mb_substr($constraintInfo['references'][0], $length); + if ($length > 0 && mb_substr((string)$constraintInfo['references'][0], 0, $length) === $this->tablePrefix) { + return mb_substr((string)$constraintInfo['references'][0], $length); } return $constraintInfo['references'][0]; @@ -724,7 +719,7 @@ public function getEntityPropertySchema(Table $model): array if ($plugin !== null) { $namespace = $plugin; } - $namespace = str_replace('/', '\\', trim($namespace, '\\')); + $namespace = str_replace('/', '\\', trim((string)$namespace, '\\')); $entityClass = $this->_entityName($association->getTarget()->getAlias()); $entityClass = '\\' . $namespace . '\Model\Entity\\' . $entityClass; @@ -894,9 +889,9 @@ public function fieldValidation( $rules['date'] = []; } elseif ($metaData['type'] === 'time') { $rules['time'] = []; - } elseif (strpos($metaData['type'], 'datetime') === 0) { + } elseif (str_starts_with((string)$metaData['type'], 'datetime')) { $rules['dateTime'] = []; - } elseif (strpos($metaData['type'], 'timestamp') === 0) { + } elseif (str_starts_with((string)$metaData['type'], 'timestamp')) { $rules['dateTime'] = []; } elseif ($metaData['type'] === 'inet') { $rules['ip'] = []; @@ -1048,7 +1043,7 @@ public function getRules(Table $model, array $associations, Arguments $args): ar } $possiblyUniqueColumns = ['username', 'login']; - if (in_array($model->getAlias(), ['Users', 'Accounts'])) { + if (in_array($model->getAlias(), ['Users', 'Accounts'], true)) { $possiblyUniqueColumns[] = 'email'; } @@ -1132,7 +1127,7 @@ public function getCounterCache(Table $model): array try { $otherSchema = $otherModel->getSchema(); - } catch (DatabaseException $e) { + } catch (DatabaseException) { continue; } @@ -1231,7 +1226,7 @@ public function bakeTable(Table $model, array $data, Arguments $args, ConsoleIo if ($args->getOption('update')) { $parsedFile = $this->parseFile($filename); // Extract custom column types from existing file - if ($parsedFile && isset($parsedFile->class->methods['initialize'])) { + if ($parsedFile instanceof ParsedFile && isset($parsedFile->class->methods['initialize'])) { $customColumnTypes = $this->extractCustomColumnTypes($parsedFile->class->methods['initialize']); } } @@ -1338,7 +1333,7 @@ public function getTable(string $name, Arguments $args): string * @param \Cake\Console\ConsoleOptionParser $parser The parser to configure * @return \Cake\Console\ConsoleOptionParser */ - public function buildOptionParser(ConsoleOptionParser $parser): ConsoleOptionParser + protected function buildOptionParser(ConsoleOptionParser $parser): ConsoleOptionParser { $parser = $this->_setCommonOptions($parser); @@ -1349,7 +1344,7 @@ public function buildOptionParser(ConsoleOptionParser $parser): ConsoleOptionPar 'You can use Plugin.name to bake plugin models.', ])->addOption('update', [ 'boolean' => true, - 'help' => 'Update generated methods in existing files. If the file doesn\'t exist it will be created.', + 'help' => "Update generated methods in existing files. If the file doesn't exist it will be created.", ])->addOption('table', [ 'help' => 'The table name to use if you have non-conventional table names.', ])->addOption('no-entity', [ @@ -1449,9 +1444,6 @@ public function bakeTest(string $className, Arguments $args, ConsoleIo $io): voi } /** - * @param \Cake\ORM\Table $table - * @param string $entity - * @param string $namespace * @return array */ protected function enums(Table $table, string $entity, string $namespace): array @@ -1473,7 +1465,6 @@ protected function enums(Table $table, string $entity, string $namespace): array } /** - * @param \Cake\Database\Schema\TableSchemaInterface $schema * @return array */ protected function possibleEnumFields(TableSchemaInterface $schema): array @@ -1483,7 +1474,7 @@ protected function possibleEnumFields(TableSchemaInterface $schema): array foreach ($schema->columns() as $column) { /** @var array $columnSchema */ $columnSchema = $schema->getColumn($column); - if (str_starts_with($columnSchema['type'], 'enum-')) { + if (str_starts_with((string)$columnSchema['type'], 'enum-')) { $fields[] = $column; continue; @@ -1500,7 +1491,6 @@ protected function possibleEnumFields(TableSchemaInterface $schema): array } /** - * @param \Cake\Database\Schema\TableSchemaInterface $schema * @return array */ protected function getEnumDefinitions(TableSchemaInterface $schema): array @@ -1512,18 +1502,18 @@ protected function getEnumDefinitions(TableSchemaInterface $schema): array $columnSchema = $schema->getColumn($column); if ( !in_array($columnSchema['type'], ['string', 'integer', 'tinyinteger', 'smallinteger'], true) - && !str_starts_with($columnSchema['type'], 'enum-') + && !str_starts_with((string)$columnSchema['type'], 'enum-') ) { continue; } - if (empty($columnSchema['comment']) || !str_contains($columnSchema['comment'], '[enum]')) { + if (empty($columnSchema['comment']) || !str_contains((string)$columnSchema['comment'], '[enum]')) { continue; } $enumsDefinitionString = EnumParser::parseDefinitionString($columnSchema['comment']); $isInt = in_array($columnSchema['type'], ['integer', 'tinyinteger', 'smallinteger'], true); - if (str_starts_with($columnSchema['type'], 'enum-')) { + if (str_starts_with((string)$columnSchema['type'], 'enum-')) { $dbType = TypeFactory::build($columnSchema['type']); if ($dbType instanceof EnumType) { $class = $dbType->getEnumClassName(); @@ -1549,10 +1539,7 @@ protected function getEnumDefinitions(TableSchemaInterface $schema): array } /** - * @param \Cake\ORM\Table $model * @param array $data - * @param \Cake\Console\Arguments $args - * @param \Cake\Console\ConsoleIo $io * @return void */ protected function bakeEnums(Table $model, array $data, Arguments $args, ConsoleIo $io): void diff --git a/src/Command/PluginCommand.php b/src/Command/PluginCommand.php index 551d10de..73665d06 100644 --- a/src/Command/PluginCommand.php +++ b/src/Command/PluginCommand.php @@ -38,8 +38,6 @@ class PluginCommand extends BakeCommand { /** * Plugin path. - * - * @var string */ public string $path; @@ -62,7 +60,7 @@ public function execute(Arguments $args, ConsoleIo $io): ?int return static::CODE_ERROR; } $parts = explode('/', $name); - $plugin = implode('/', array_map([Inflector::class, 'camelize'], $parts)); + $plugin = implode('/', array_map(Inflector::camelize(...), $parts)); if ($args->getOption('standalone-path')) { $this->path = (string)$args->getOption('standalone-path'); @@ -256,7 +254,7 @@ protected function _generateFiles( } if ($args->getOption('class-only')) { - $files = array_filter($files, function ($file) { + $files = array_filter($files, function ($file): bool { return $file->getFilename() === 'Plugin.php.twig'; }); } @@ -267,7 +265,7 @@ protected function _generateFiles( sort($templates); foreach ($templates as $template) { - $template = substr($template, strrpos($template, 'Plugin' . DIRECTORY_SEPARATOR) + 7, -4); + $template = substr((string)$template, strrpos((string)$template, 'Plugin' . DIRECTORY_SEPARATOR) + 7, -4); $template = rtrim($template, '.'); $filename = $template; if ($filename === 'src' . DIRECTORY_SEPARATOR . 'Plugin.php') { @@ -360,7 +358,7 @@ public function findPath(array $pathOptions, ConsoleIo $io): void * @param \Cake\Console\ConsoleOptionParser $parser The option parser * @return \Cake\Console\ConsoleOptionParser */ - public function buildOptionParser(ConsoleOptionParser $parser): ConsoleOptionParser + protected function buildOptionParser(ConsoleOptionParser $parser): ConsoleOptionParser { $parser->setDescription( 'Create the directory structure, AppController class and testing setup for a new plugin. ' . diff --git a/src/Command/SimpleBakeCommand.php b/src/Command/SimpleBakeCommand.php index 2df9572a..a9667a22 100644 --- a/src/Command/SimpleBakeCommand.php +++ b/src/Command/SimpleBakeCommand.php @@ -135,7 +135,7 @@ public function bakeTest(string $className, Arguments $args, ConsoleIo $io): voi * @param \Cake\Console\ConsoleOptionParser $parser Option parser to update. * @return \Cake\Console\ConsoleOptionParser */ - public function buildOptionParser(ConsoleOptionParser $parser): ConsoleOptionParser + protected function buildOptionParser(ConsoleOptionParser $parser): ConsoleOptionParser { $parser = $this->_setCommonOptions($parser); $name = $this->name(); diff --git a/src/Command/TemplateAllCommand.php b/src/Command/TemplateAllCommand.php index 45e14ef1..0a1c72e5 100644 --- a/src/Command/TemplateAllCommand.php +++ b/src/Command/TemplateAllCommand.php @@ -27,9 +27,6 @@ */ class TemplateAllCommand extends BakeCommand { - /** - * @var \Bake\Command\TemplateCommand - */ protected TemplateCommand $templateCommand; /** @@ -86,7 +83,7 @@ public function execute(Arguments $args, ConsoleIo $io): int * @param \Cake\Console\ConsoleOptionParser $parser The option parser to update. * @return \Cake\Console\ConsoleOptionParser */ - public function buildOptionParser(ConsoleOptionParser $parser): ConsoleOptionParser + protected function buildOptionParser(ConsoleOptionParser $parser): ConsoleOptionParser { $parser = $this->_setCommonOptions($parser); $parser diff --git a/src/Command/TemplateCommand.php b/src/Command/TemplateCommand.php index 64619f00..b41707df 100644 --- a/src/Command/TemplateCommand.php +++ b/src/Command/TemplateCommand.php @@ -39,22 +39,16 @@ class TemplateCommand extends BakeCommand { /** * Name of the controller being used - * - * @var string */ public string $controllerName; /** * Classname of the controller being used - * - * @var string */ public string $controllerClass; /** * Name with plugin of the model being used - * - * @var string */ public string $modelName; @@ -74,22 +68,16 @@ class TemplateCommand extends BakeCommand /** * AssociationFilter utility - * - * @var \Bake\Utility\Model\AssociationFilter|null */ protected ?AssociationFilter $_associationFilter = null; /** * Template path. - * - * @var string */ public string $path; /** * Output extension - * - * @var string */ public string $ext = 'php'; @@ -180,7 +168,7 @@ public function model(string $table): void $tableName = $this->_camelize($table); $plugin = $this->plugin; if ($plugin) { - $plugin = $plugin . '.'; + $plugin .= '.'; } $this->modelName = $plugin . $tableName; } @@ -222,9 +210,8 @@ public function controller(Arguments $args, string $table, ?string $controller = public function getTemplatePath(Arguments $args, ?string $container = null): string { $path = parent::getTemplatePath($args, $container); - $path .= $this->controllerName . DS; - return $path; + return $path . $this->controllerName . DS; } /** @@ -421,7 +408,7 @@ public function getContent(Arguments $args, ConsoleIo $io, string $action, ?arra } $renderer->set('indexColumns', $indexColumns); - return $renderer->generate("Bake.Template/$action"); + return $renderer->generate("Bake.Template/{$action}"); } /** @@ -430,7 +417,7 @@ public function getContent(Arguments $args, ConsoleIo $io, string $action, ?arra * @param \Cake\Console\ConsoleOptionParser $parser The option parser to update. * @return \Cake\Console\ConsoleOptionParser */ - public function buildOptionParser(ConsoleOptionParser $parser): ConsoleOptionParser + protected function buildOptionParser(ConsoleOptionParser $parser): ConsoleOptionParser { $parser = $this->_setCommonOptions($parser); @@ -463,7 +450,7 @@ public function buildOptionParser(ConsoleOptionParser $parser): ConsoleOptionPar */ protected function _filteredAssociations(Table $model): array { - if ($this->_associationFilter === null) { + if (!$this->_associationFilter instanceof AssociationFilter) { $this->_associationFilter = new AssociationFilter(); } diff --git a/src/Command/TestCommand.php b/src/Command/TestCommand.php index 0231bf88..c62c4c19 100644 --- a/src/Command/TestCommand.php +++ b/src/Command/TestCommand.php @@ -149,7 +149,7 @@ protected function outputTypeChoices(ConsoleIo $io): void 2, ); $i = 0; - foreach ($this->classTypes as $option => $package) { + foreach (array_keys($this->classTypes) as $option) { $io->out(++$i . '. ' . $option); } $io->out(''); @@ -228,19 +228,15 @@ protected function _getClassOptions(string $namespace): array /** @var string $relativePath */ $relativePath = str_replace($base, '', $fileObj->getPath()); $relativePath = trim(str_replace(DIRECTORY_SEPARATOR, '\\', $relativePath), '\\'); - $className = substr($fileObj->getFileName(), 0, -4) ?: ''; - if ($relativePath) { - $classes[] = $relativePath . '\\' . $className; - } else { - $classes[] = $className; - } + $className = substr((string)$fileObj->getFileName(), 0, -4) ?: ''; + $classes[] = $relativePath ? $relativePath . '\\' . $className : $className; } } } else { $files = (new Filesystem())->find($path); foreach ($files as $fileObj) { if ($fileObj->isFile()) { - $classes[] = substr($fileObj->getFileName(), 0, -4) ?: ''; + $classes[] = substr((string)$fileObj->getFileName(), 0, -4) ?: ''; } } } @@ -332,7 +328,7 @@ public function bake(string $type, string $className, Arguments $args, ConsoleIo if ($this->plugin) { $baseNamespace = $this->_pluginNamespace($this->plugin); } - $subNamespace = substr($namespace, strlen($baseNamespace) + 1); + $subNamespace = substr($namespace, strlen((string)$baseNamespace) + 1); $properties = $this->generateProperties($type, $subject, $fullClassName); @@ -445,7 +441,7 @@ public function getRealClassName(string $type, string $class, ?string $prefix = if ($type === 'Class') { // Strip base namespace if user included it if (str_starts_with($class, $namespace . '\\')) { - $class = substr($class, strlen($namespace) + 1); + $class = substr($class, strlen((string)$namespace) + 1); } return $namespace . '\\' . $class; @@ -453,7 +449,7 @@ public function getRealClassName(string $type, string $class, ?string $prefix = $suffix = $this->classSuffixes[$type]; $subSpace = $this->mapType($type); - if ($suffix && strpos($class, $suffix) === false) { + if ($suffix && !str_contains($class, $suffix)) { $class .= $suffix; } if (in_array($type, ['Controller', 'Cell'], true) && $prefix) { @@ -549,9 +545,9 @@ protected function _processModel(Table $subject): void $assoc = $subject->getAssociation($alias); $target = $assoc->getTarget(); $name = $target->getAlias(); - $subjectClass = get_class($subject); + $subjectClass = $subject::class; - if ($subjectClass !== Table::class && $subjectClass === get_class($target)) { + if ($subjectClass !== Table::class && $subjectClass === $target::class) { continue; } if (!isset($this->_fixtures[$name])) { @@ -571,7 +567,7 @@ protected function _processController(Controller $subject): void { try { $model = $subject->fetchTable(); - } catch (UnexpectedValueException $exception) { + } catch (UnexpectedValueException) { // No fixtures needed or possible return; } @@ -592,11 +588,7 @@ protected function _processController(Controller $subject): void */ protected function _addFixture(string $name): void { - if ($this->plugin) { - $prefix = 'plugin.' . $this->plugin . '.'; - } else { - $prefix = 'app.'; - } + $prefix = $this->plugin ? 'plugin.' . $this->plugin . '.' : 'app.'; $fixture = $prefix . $this->_fixtureName($name); $this->_fixtures[$name] = $fixture; } @@ -774,12 +766,11 @@ public function generateUses(string $type, string $fullClassName): array public function getBasePath(): string { $dir = 'TestCase/'; - $path = defined('TESTS') ? TESTS . $dir : ROOT . DS . 'tests' . DS . $dir; if ($this->plugin) { - $path = $this->_pluginPath($this->plugin) . 'tests/' . $dir; + return $this->_pluginPath($this->plugin) . 'tests/' . $dir; } - return $path; + return defined('TESTS') ? TESTS . $dir : ROOT . DS . 'tests' . DS . $dir; } /** @@ -798,7 +789,7 @@ public function testCaseFileName(string $type, string $className): string $namespace = $this->plugin; } - $classTail = substr($className, strlen($namespace) + 1); + $classTail = substr($className, strlen((string)$namespace) + 1); $path = $path . $classTail . 'Test.php'; return str_replace(['/', '\\'], DS, $path); @@ -810,12 +801,12 @@ public function testCaseFileName(string $type, string $className): string * @param \Cake\Console\ConsoleOptionParser $parser Option parser to update * @return \Cake\Console\ConsoleOptionParser */ - public function buildOptionParser(ConsoleOptionParser $parser): ConsoleOptionParser + protected function buildOptionParser(ConsoleOptionParser $parser): ConsoleOptionParser { $parser = $this->_setCommonOptions($parser); $types = array_keys($this->classTypes); - $types = array_merge($types, array_map([$this, 'underscore'], $types)); + $types = array_merge($types, array_map($this->underscore(...), $types)); $parser->setDescription( 'Bake test case skeletons for classes.', diff --git a/src/Utility/CommonOptionsTrait.php b/src/Utility/CommonOptionsTrait.php index b2a379f9..29541216 100644 --- a/src/Utility/CommonOptionsTrait.php +++ b/src/Utility/CommonOptionsTrait.php @@ -30,24 +30,12 @@ */ trait CommonOptionsTrait { - /** - * @var string - */ public ?string $plugin = null; - /** - * @var string|null - */ public ?string $theme = null; - /** - * @var string - */ public string $connection; - /** - * @var bool - */ public bool $force = false; /** diff --git a/src/Utility/Model/AssociationFilter.php b/src/Utility/Model/AssociationFilter.php index 3ed03932..db3d1692 100644 --- a/src/Utility/Model/AssociationFilter.php +++ b/src/Utility/Model/AssociationFilter.php @@ -78,11 +78,11 @@ public function filterAssociations(Table $model): array if ($type === 'HasMany' && in_array($alias, $belongsToManyJunctionsAliases)) { continue; } - $targetClass = get_class($target); + $targetClass = $target::class; [, $className] = namespaceSplit($targetClass); $navLink = true; - $modelClass = get_class($model); + $modelClass = $model::class; if ($modelClass !== Table::class && $targetClass === $modelClass) { $navLink = false; } @@ -105,7 +105,7 @@ public function filterAssociations(Table $model): array 'fields' => array_values(array_diff($target->getSchema()->columns(), $foreignKey)), 'navLink' => $navLink, ]; - } catch (Exception $e) { + } catch (Exception) { // Do nothing it could be a bogus association name. } } diff --git a/src/Utility/Model/EnumParser.php b/src/Utility/Model/EnumParser.php index 3cf32999..ac80024b 100644 --- a/src/Utility/Model/EnumParser.php +++ b/src/Utility/Model/EnumParser.php @@ -8,8 +8,6 @@ class EnumParser { /** - * @param string|null $casesString - * @param bool $int * @return array */ public static function parseCases(?string $casesString, bool $int): array @@ -34,8 +32,8 @@ public static function parseCases(?string $casesString, bool $int): array if (!preg_match('/^[a-zA-Z_\x80-\xff][a-zA-Z0-9_\x80-\xff]*$/', $case)) { throw new InvalidArgumentException(sprintf('`%s` is not a valid enum case', $case)); } - if (is_string($value) && str_contains($value, '\'')) { - throw new InvalidArgumentException(sprintf('`%s` value cannot contain `\'` character', $case)); + if (is_string($value) && str_contains($value, "'")) { + throw new InvalidArgumentException(sprintf("`%s` value cannot contain `'` character", $case)); } $definition[$case] = $int ? (int)$value : $value; @@ -47,7 +45,6 @@ public static function parseCases(?string $casesString, bool $int): array /** * Parses an enum definition from a DB column comment. * - * @param string $comment * @return string */ public static function parseDefinitionString(string $comment): string @@ -55,7 +52,7 @@ public static function parseDefinitionString(string $comment): string $string = trim(mb_substr($comment, strpos($comment, '[enum]') + 6)); $pos = strpos($string, ';'); if ($pos !== false) { - $string = trim(mb_substr($string, 0, $pos)); + return trim(mb_substr($string, 0, $pos)); } return $string; diff --git a/src/Utility/Process.php b/src/Utility/Process.php index 78686c33..27c9cc15 100644 --- a/src/Utility/Process.php +++ b/src/Utility/Process.php @@ -26,9 +26,6 @@ */ class Process { - /** - * @var \Cake\Console\ConsoleIo - */ protected ConsoleIo $io; /** @@ -62,7 +59,7 @@ public function call(string $command): string $pipes, ); if (!is_resource($process)) { - throw new RuntimeException("Could not start subprocess for `$command`"); + throw new RuntimeException("Could not start subprocess for `{$command}`"); } fclose($pipes[0]); diff --git a/src/Utility/SubsetSchemaCollection.php b/src/Utility/SubsetSchemaCollection.php index 6f202c08..995a31e6 100644 --- a/src/Utility/SubsetSchemaCollection.php +++ b/src/Utility/SubsetSchemaCollection.php @@ -27,9 +27,6 @@ */ class SubsetSchemaCollection implements CollectionInterface { - /** - * @var \Cake\Database\Schema\CollectionInterface - */ protected CollectionInterface $collection; /** diff --git a/src/Utility/TableScanner.php b/src/Utility/TableScanner.php index b10be2c0..64e1c87f 100644 --- a/src/Utility/TableScanner.php +++ b/src/Utility/TableScanner.php @@ -29,9 +29,6 @@ */ class TableScanner { - /** - * @var \Cake\Database\Connection - */ protected Connection $connection; /** @@ -120,10 +117,8 @@ public function removeShadowTranslationTables(array $tables): array protected function shouldSkip(string $table): bool { foreach ($this->ignore as $ignore) { - if (str_starts_with($ignore, '/')) { - if ((bool)preg_match($ignore, $table)) { - return true; - } + if (str_starts_with($ignore, '/') && (bool)preg_match($ignore, $table)) { + return true; } if ($ignore === $table) { diff --git a/src/Utility/TemplateRenderer.php b/src/Utility/TemplateRenderer.php index 42996b97..7566cd07 100644 --- a/src/Utility/TemplateRenderer.php +++ b/src/Utility/TemplateRenderer.php @@ -34,15 +34,11 @@ class TemplateRenderer /** * BakeView instance - * - * @var \Bake\View\BakeView|null */ protected ?BakeView $view = null; /** * Template theme - * - * @var string|null */ protected ?string $theme; @@ -64,7 +60,7 @@ public function __construct(?string $theme = null) */ public function getView(): View { - if ($this->view) { + if ($this->view instanceof BakeView) { return $this->view; } @@ -99,7 +95,7 @@ public function generate(string $template, ?array $vars = null): string try { return $view->render($template); - } catch (MissingTemplateException $e) { + } catch (MissingTemplateException) { $message = sprintf('No bake template found for "%s" skipping file generation.', $template); throw new MissingTemplateException($message); } diff --git a/src/View/BakeView.php b/src/View/BakeView.php index 78928f10..ebc623df 100644 --- a/src/View/BakeView.php +++ b/src/View/BakeView.php @@ -132,7 +132,7 @@ protected function _paths(?string $plugin = null, bool $cached = true): array $paths = parent::_paths($plugin, false); foreach ($paths as &$path) { // Append 'bake' to all directories that aren't the application override directory. - if (strpos($path, 'plugin' . DS . 'Bake') === false) { + if (!str_contains($path, 'plugin' . DS . 'Bake')) { $path .= static::BAKE_TEMPLATE_FOLDER . DS; } } diff --git a/src/View/Helper/BakeHelper.php b/src/View/Helper/BakeHelper.php index 51aa44a2..e73388c6 100644 --- a/src/View/Helper/BakeHelper.php +++ b/src/View/Helper/BakeHelper.php @@ -37,8 +37,6 @@ class BakeHelper extends Helper /** * AssociationFilter utility - * - * @var \Bake\Utility\Model\AssociationFilter|null */ protected ?AssociationFilter $_associationFilter = null; @@ -152,7 +150,7 @@ public function classInfo(string $class, string $type, string $suffix): array if ($plugin !== null) { $base = $plugin; } - $base = str_replace('/', '\\', trim($base, '\\')); + $base = str_replace('/', '\\', trim((string)$base, '\\')); $sub = '\\' . str_replace('/', '\\', trim($type, '\\')); $qn = $sub . '\\' . $name . $suffix; @@ -198,12 +196,12 @@ public function filterFields( array $filterTypes = ['binary'], ): array { $fields = collection($fields) - ->filter(function ($field) use ($schema, $filterTypes) { + ->filter(function ($field) use ($schema, $filterTypes): bool { return !in_array($schema->getColumnType($field), $filterTypes); }); if (isset($modelObject) && $modelObject->hasBehavior('Tree')) { - $fields = $fields->reject(function ($field) { + $fields = $fields->reject(function ($field): bool { return $field === 'lft' || $field === 'rght'; }); } @@ -235,15 +233,15 @@ public function getViewFieldsData(array $fields, SchemaInterface $schema, array } }) ->filter() - ->reduce(function ($fields, $value) { + ->reduce(function ($fields, $value): float|int|array { return $fields + $value; }, []); $groupedFields = collection($fields) - ->filter(function ($field) use ($schema) { + ->filter(function ($field) use ($schema): bool { return $schema->getColumnType($field) !== 'binary'; }) - ->groupBy(function ($field) use ($schema, $associationFields) { + ->groupBy(function ($field) use ($schema, $associationFields): string { $type = $schema->getColumnType($field); if (isset($associationFields[$field])) { return 'string'; @@ -264,11 +262,11 @@ public function getViewFieldsData(array $fields, SchemaInterface $schema, array 'timestampfractional', 'timestamptimezone', ]; - if (in_array($type, $dateTypes)) { + if (in_array($type, $dateTypes, true)) { return 'date'; } - return in_array($type, ['text', 'boolean']) ? $type : 'string'; + return in_array($type, ['text', 'boolean'], true) ? $type : 'string'; }) ->toArray(); @@ -367,7 +365,7 @@ public function getValidationMethods(string $field, array $rules): array continue; } - $rule['args'] = array_map(function ($item) { + $rule['args'] = array_map(function ($item): string { return $this->exportVar( $item, is_array($item) ? 3 : 0, @@ -423,7 +421,7 @@ public function escapeArguments(array $args): array return array_map(function ($v) { if (is_string($v)) { $v = strtr($v, ["'" => "\'"]); - $v = "'$v'"; + $v = "'{$v}'"; } return $v; @@ -496,7 +494,7 @@ public function getConstUses(array $imports): string */ protected function getUseType(string $alias, string $name): string { - if ($name == $alias || substr($name, -strlen("\\{$alias}")) === "\\{$alias}") { + if ($name === $alias || str_ends_with($name, "\\{$alias}")) { return $name; } @@ -520,7 +518,7 @@ public function concat( ): string { $output = implode( $delimiter, - array_map(function ($string) use ($delimiter) { + array_map(function ($string) use ($delimiter): string { if (is_string($string)) { return $string; } diff --git a/src/View/Helper/DocBlockHelper.php b/src/View/Helper/DocBlockHelper.php index a0618413..014c3d9b 100644 --- a/src/View/Helper/DocBlockHelper.php +++ b/src/View/Helper/DocBlockHelper.php @@ -59,7 +59,7 @@ public function classDescription(string $className, string $classType, array $an $lines[] = $annotation; } - $lines = array_merge(['/**'], (new Collection($lines))->map(function ($line) { + $lines = array_merge(['/**'], (new Collection($lines))->map(function ($line): string { return rtrim(" * {$line}"); })->toArray(), [' */']); @@ -307,7 +307,7 @@ public function buildTableAnnotations( $annotations[] = "@method iterable<\\{$namespace}\\Model\\Entity\\{$entity}>|\Cake\Datasource\ResultSetInterface<\\{$namespace}\\Model\\Entity\\{$entity}>|false deleteMany(iterable \$entities, array \$options = [])"; $annotations[] = "@method iterable<\\{$namespace}\\Model\\Entity\\{$entity}>|\Cake\Datasource\ResultSetInterface<\\{$namespace}\\Model\\Entity\\{$entity}> deleteManyOrFail(iterable \$entities, array \$options = [])"; // phpcs:enable - foreach ($behaviors as $behavior => $behaviorData) { + foreach (array_keys($behaviors) as $behavior) { $className = App::className($behavior, 'Model/Behavior', 'Behavior'); if (!$className) { $className = "Cake\ORM\Behavior\\{$behavior}Behavior"; @@ -331,12 +331,12 @@ public function buildTableAnnotations( */ protected function _insertAfter(array $target, string $key, mixed $value): array { - $index = array_search($key, array_keys($target)); + $index = array_search($key, array_keys($target), true); if ($index !== false) { $target = array_merge( array_slice($target, 0, $index + 1), $value, - array_slice($target, $index + 1, null), + array_slice($target, $index + 1), ); } else { $target += (array)$value; diff --git a/tests/Fixture/BakeCarFixture.php b/tests/Fixture/BakeCarFixture.php index 5fa12baa..f3783dd4 100644 --- a/tests/Fixture/BakeCarFixture.php +++ b/tests/Fixture/BakeCarFixture.php @@ -21,8 +21,5 @@ */ class BakeCarFixture extends TestFixture { - /** - * @var string - */ public string $table = 'car'; } diff --git a/tests/Fixture/BakeTemplateAuthorsFixture.php b/tests/Fixture/BakeTemplateAuthorsFixture.php index eaa86a68..50441ed2 100644 --- a/tests/Fixture/BakeTemplateAuthorsFixture.php +++ b/tests/Fixture/BakeTemplateAuthorsFixture.php @@ -24,15 +24,11 @@ class BakeTemplateAuthorsFixture extends TestFixture { /** * Avoid overriding AuthorsFixture's table. - * - * @var string */ public string $table = 'bake_authors'; /** * records property - * - * @var array */ public array $records = [ ['name' => 'mariano', 'role_id' => 1], diff --git a/tests/Fixture/BakeTemplateProfilesFixture.php b/tests/Fixture/BakeTemplateProfilesFixture.php index 50fba6d8..8dfc8aa0 100644 --- a/tests/Fixture/BakeTemplateProfilesFixture.php +++ b/tests/Fixture/BakeTemplateProfilesFixture.php @@ -24,15 +24,10 @@ */ class BakeTemplateProfilesFixture extends TestFixture { - /** - * @var string - */ public string $table = 'profiles'; /** * records property - * - * @var array */ public array $records = [ ['author_id' => 1, 'nick' => 'The Comedian', 'avatar' => 'smiley.png'], diff --git a/tests/Fixture/BakeTemplateRolesFixture.php b/tests/Fixture/BakeTemplateRolesFixture.php index ed1cd3fc..dd1887c9 100644 --- a/tests/Fixture/BakeTemplateRolesFixture.php +++ b/tests/Fixture/BakeTemplateRolesFixture.php @@ -21,15 +21,10 @@ */ class BakeTemplateRolesFixture extends TestFixture { - /** - * @var string - */ public string $table = 'roles'; /** * records property - * - * @var array */ public array $records = [ ['name' => 'admin'], diff --git a/tests/Fixture/CategoriesFixture.php b/tests/Fixture/CategoriesFixture.php index 0ab0d4e1..f862a1f5 100644 --- a/tests/Fixture/CategoriesFixture.php +++ b/tests/Fixture/CategoriesFixture.php @@ -23,8 +23,6 @@ class CategoriesFixture extends TestFixture { /** * Records - * - * @var array */ public array $records = [ [ diff --git a/tests/Fixture/CategoriesProductsFixture.php b/tests/Fixture/CategoriesProductsFixture.php index c66ac82a..848242a2 100644 --- a/tests/Fixture/CategoriesProductsFixture.php +++ b/tests/Fixture/CategoriesProductsFixture.php @@ -23,8 +23,6 @@ class CategoriesProductsFixture extends TestFixture { /** * Records - * - * @var array */ public array $records = [ [ diff --git a/tests/Fixture/CategoryThreadsFixture.php b/tests/Fixture/CategoryThreadsFixture.php index 3142e376..2c7f983a 100644 --- a/tests/Fixture/CategoryThreadsFixture.php +++ b/tests/Fixture/CategoryThreadsFixture.php @@ -23,8 +23,6 @@ class CategoryThreadsFixture extends TestFixture { /** * records property - * - * @var array */ public array $records = [ ['parent_id' => 0, 'name' => 'Category 1', 'lft' => 1, 'rght' => 14, 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'], diff --git a/tests/Fixture/DatatypesFixture.php b/tests/Fixture/DatatypesFixture.php index addc7cee..7748da66 100644 --- a/tests/Fixture/DatatypesFixture.php +++ b/tests/Fixture/DatatypesFixture.php @@ -23,8 +23,6 @@ class DatatypesFixture extends TestFixture { /** * Records property - * - * @var array */ public array $records = [ ['decimal_field' => '30.123', 'float_field' => 42.23, 'huge_int' => '1234567891234567891', 'small_int' => '1234', 'tiny_int' => '12', 'bool' => 0, 'timestamp_field' => '2007-03-17 01:16:23'], diff --git a/tests/Fixture/HiddenFieldsFixture.php b/tests/Fixture/HiddenFieldsFixture.php index 7fd63501..3e8da261 100644 --- a/tests/Fixture/HiddenFieldsFixture.php +++ b/tests/Fixture/HiddenFieldsFixture.php @@ -23,8 +23,6 @@ class HiddenFieldsFixture extends TestFixture { /** * records property - * - * @var array */ public array $records = [ ['password' => '$2a$10$u05j8FjsvLBNdfhBhc21LOuVMpzpabVXQ9OpC2wO3pSO0q6t7HHMO', 'auth_token' => '12345'], diff --git a/tests/Fixture/InvitationsFixture.php b/tests/Fixture/InvitationsFixture.php index e6606917..be1ee8bb 100644 --- a/tests/Fixture/InvitationsFixture.php +++ b/tests/Fixture/InvitationsFixture.php @@ -23,8 +23,6 @@ class InvitationsFixture extends TestFixture { /** * records property - * - * @var array */ public array $records = [ [ diff --git a/tests/Fixture/OldProductsFixture.php b/tests/Fixture/OldProductsFixture.php index 8e6d3ac8..7bf36fa6 100644 --- a/tests/Fixture/OldProductsFixture.php +++ b/tests/Fixture/OldProductsFixture.php @@ -23,8 +23,6 @@ class OldProductsFixture extends TestFixture { /** * Records - * - * @var array */ public array $records = [ [ diff --git a/tests/Fixture/ProductVersionsFixture.php b/tests/Fixture/ProductVersionsFixture.php index bd04c6cf..36d6334f 100644 --- a/tests/Fixture/ProductVersionsFixture.php +++ b/tests/Fixture/ProductVersionsFixture.php @@ -23,8 +23,6 @@ class ProductVersionsFixture extends TestFixture { /** * Records - * - * @var array */ public array $records = [ [ diff --git a/tests/Fixture/ProductsFixture.php b/tests/Fixture/ProductsFixture.php index 381c45d1..83a59b5d 100644 --- a/tests/Fixture/ProductsFixture.php +++ b/tests/Fixture/ProductsFixture.php @@ -23,8 +23,6 @@ class ProductsFixture extends TestFixture { /** * Records - * - * @var array */ public array $records = [ [ diff --git a/tests/Fixture/RelationsFixture.php b/tests/Fixture/RelationsFixture.php index d7b09a1f..8daa7974 100644 --- a/tests/Fixture/RelationsFixture.php +++ b/tests/Fixture/RelationsFixture.php @@ -23,8 +23,6 @@ class RelationsFixture extends TestFixture { /** * records property - * - * @var array */ public array $records = [ [ diff --git a/tests/Fixture/UniqueFieldsFixture.php b/tests/Fixture/UniqueFieldsFixture.php index 34e0a37d..a9cd0154 100644 --- a/tests/Fixture/UniqueFieldsFixture.php +++ b/tests/Fixture/UniqueFieldsFixture.php @@ -23,8 +23,6 @@ class UniqueFieldsFixture extends TestFixture { /** * records property - * - * @var array */ public array $records = [ ['field_1' => 'unique_value_1', 'field_2' => 'unique_value_2'], diff --git a/tests/Fixture/UsersFixture.php b/tests/Fixture/UsersFixture.php index a98fb40b..89fd55ce 100644 --- a/tests/Fixture/UsersFixture.php +++ b/tests/Fixture/UsersFixture.php @@ -23,8 +23,6 @@ class UsersFixture extends TestFixture { /** * records property - * - * @var array */ public array $records = [ ['username' => 'mariano', 'password' => '$2a$10$u05j8FjsvLBNdfhBhc21LOuVMpzpabVXQ9OpC2wO3pSO0q6t7HHMO', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'], diff --git a/tests/TestCase/CodeGen/ClassBuilderTest.php b/tests/TestCase/CodeGen/ClassBuilderTest.php index c0b0d803..2fe69cb5 100644 --- a/tests/TestCase/CodeGen/ClassBuilderTest.php +++ b/tests/TestCase/CodeGen/ClassBuilderTest.php @@ -29,7 +29,7 @@ class ClassBuilderTest extends TestCase */ protected $io; - public function setUp(): void + protected function setUp(): void { parent::setUp(); $this->io = new ConsoleIo(new StubConsoleOutput()); diff --git a/tests/TestCase/CodeGen/ColumnTypeExtractorTest.php b/tests/TestCase/CodeGen/ColumnTypeExtractorTest.php index af8867fc..5dece583 100644 --- a/tests/TestCase/CodeGen/ColumnTypeExtractorTest.php +++ b/tests/TestCase/CodeGen/ColumnTypeExtractorTest.php @@ -24,9 +24,6 @@ */ class ColumnTypeExtractorTest extends TestCase { - /** - * @var \Bake\CodeGen\ColumnTypeExtractor - */ protected ColumnTypeExtractor $extractor; /** @@ -34,7 +31,7 @@ class ColumnTypeExtractorTest extends TestCase * * @return void */ - public function setUp(): void + protected function setUp(): void { parent::setUp(); $this->extractor = new ColumnTypeExtractor(); diff --git a/tests/TestCase/CodeGen/FileBuilderTest.php b/tests/TestCase/CodeGen/FileBuilderTest.php index 5b20ff2c..8eb62e96 100644 --- a/tests/TestCase/CodeGen/FileBuilderTest.php +++ b/tests/TestCase/CodeGen/FileBuilderTest.php @@ -36,7 +36,7 @@ class FileBuilderTest extends TestCase */ protected $io; - public function setUp(): void + protected function setUp(): void { parent::setUp(); $this->out = new StubConsoleOutput(); diff --git a/tests/TestCase/Command/AllCommandTest.php b/tests/TestCase/Command/AllCommandTest.php index 7aebae10..49caf221 100644 --- a/tests/TestCase/Command/AllCommandTest.php +++ b/tests/TestCase/Command/AllCommandTest.php @@ -46,7 +46,7 @@ class AllCommandTest extends TestCase * * @return void */ - public function setUp(): void + protected function setUp(): void { parent::setUp(); @@ -62,7 +62,7 @@ public function setUp(): void * * @return void */ - public function tearDown(): void + protected function tearDown(): void { parent::tearDown(); $connection = ConnectionManager::get('test'); @@ -74,7 +74,7 @@ public function tearDown(): void * * @return void */ - public function testExecute() + public function testExecute(): void { $path = APP; $testsPath = ROOT . 'tests' . DS; @@ -104,7 +104,7 @@ public function testExecute() * * @return void */ - public function testExecuteEverything() + public function testExecuteEverything(): void { $path = APP; $testsPath = ROOT . 'tests' . DS; @@ -145,7 +145,7 @@ public function testExecuteEverything() * * @return void */ - public function testExecuteWithPrefix() + public function testExecuteWithPrefix(): void { $path = APP; $testsPath = ROOT . 'tests' . DS; @@ -191,7 +191,7 @@ public function testExecuteWithPrefix() * * @return void */ - public function testGenerateLinkDocBlockController() + public function testGenerateLinkDocBlockController(): void { $path = APP; $testsPath = ROOT . 'tests' . DS; diff --git a/tests/TestCase/Command/CellCommandTest.php b/tests/TestCase/Command/CellCommandTest.php index 3c0308df..10be3815 100644 --- a/tests/TestCase/Command/CellCommandTest.php +++ b/tests/TestCase/Command/CellCommandTest.php @@ -30,7 +30,7 @@ class CellCommandTest extends TestCase * * @return void */ - public function setUp(): void + protected function setUp(): void { parent::setUp(); $this->_compareBasePath = Plugin::path('Bake') . 'tests' . DS . 'comparisons' . DS . 'Cell' . DS; @@ -43,7 +43,7 @@ public function setUp(): void * * @return void */ - public function testMain() + public function testMain(): void { $this->generatedFiles = [ APP . 'View/Cell/ExampleCell.php', @@ -62,7 +62,7 @@ public function testMain() * * @return void */ - public function testMainPlugin() + public function testMainPlugin(): void { $this->_loadTestPlugin('TestBake'); $path = Plugin::path('TestBake'); @@ -84,7 +84,7 @@ public function testMainPlugin() * * @return void */ - public function testBakePlugin() + public function testBakePlugin(): void { $this->_loadTestPlugin('TestBake'); $path = Plugin::path('TestBake'); @@ -105,7 +105,7 @@ public function testBakePlugin() * * @return void */ - public function testMainPrefix() + public function testMainPrefix(): void { $this->generatedFiles = [ APP . 'View/Cell/Admin/ExampleCell.php', @@ -125,7 +125,7 @@ public function testMainPrefix() * * @return void */ - public function testMainPrefixPlugin() + public function testMainPrefixPlugin(): void { $this->_loadTestPlugin('TestBake'); $path = Plugin::path('TestBake'); diff --git a/tests/TestCase/Command/CommandCommandTest.php b/tests/TestCase/Command/CommandCommandTest.php index 4f049845..4a21c6e0 100644 --- a/tests/TestCase/Command/CommandCommandTest.php +++ b/tests/TestCase/Command/CommandCommandTest.php @@ -30,7 +30,7 @@ class CommandCommandTest extends TestCase * * @return void */ - public function setUp(): void + protected function setUp(): void { parent::setUp(); $this->_compareBasePath = Plugin::path('Bake') . 'tests' . DS . 'comparisons' . DS . 'Command' . DS; @@ -42,7 +42,7 @@ public function setUp(): void * * @return void */ - public function testMain() + public function testMain(): void { $this->generatedFiles = [ APP . 'Command/ExampleCommand.php', @@ -60,7 +60,7 @@ public function testMain() * * @return void */ - public function testMainPlugin() + public function testMainPlugin(): void { $this->_loadTestPlugin('TestBake'); $path = Plugin::path('TestBake'); @@ -81,7 +81,7 @@ public function testMainPlugin() * * @return void */ - public function testBakePlugin() + public function testBakePlugin(): void { $this->_loadTestPlugin('TestBake'); $path = Plugin::path('TestBake'); @@ -101,7 +101,7 @@ public function testBakePlugin() * * @return void */ - public function testGenerateUsesDocBlock() + public function testGenerateUsesDocBlock(): void { $testsPath = ROOT . 'tests' . DS; @@ -128,7 +128,7 @@ public function testGenerateUsesDocBlock() * * @return void */ - public function testGenerateUsesDocBlockPlugin() + public function testGenerateUsesDocBlockPlugin(): void { $path = Plugin::path('BakeTest'); diff --git a/tests/TestCase/Command/CommandHelperTest.php b/tests/TestCase/Command/CommandHelperTest.php index 9d0a40f4..01fa12bc 100644 --- a/tests/TestCase/Command/CommandHelperTest.php +++ b/tests/TestCase/Command/CommandHelperTest.php @@ -30,7 +30,7 @@ class CommandHelperTest extends TestCase * * @return void */ - public function setUp(): void + protected function setUp(): void { parent::setUp(); $this->_compareBasePath = Plugin::path('Bake') . 'tests' . DS . 'comparisons' . DS . 'Command' . DS; @@ -42,7 +42,7 @@ public function setUp(): void * * @return void */ - public function testBakeCommandHelper() + public function testBakeCommandHelper(): void { $this->generatedFiles = [ APP . 'Command/Helper/ErrorHelper.php', @@ -63,7 +63,7 @@ public function testBakeCommandHelper() * * @return void */ - public function testBakeCommandHelperPlugin() + public function testBakeCommandHelperPlugin(): void { $this->_loadTestPlugin('TestBake'); $path = Plugin::path('TestBake'); diff --git a/tests/TestCase/Command/ControllerAllCommandTest.php b/tests/TestCase/Command/ControllerAllCommandTest.php index d456cc02..4b70b5d1 100644 --- a/tests/TestCase/Command/ControllerAllCommandTest.php +++ b/tests/TestCase/Command/ControllerAllCommandTest.php @@ -47,7 +47,7 @@ class ControllerAllCommandTest extends TestCase * * @return void */ - public function setUp(): void + protected function setUp(): void { parent::setUp(); $this->_compareBasePath = Plugin::path('Bake') . 'tests' . DS . 'comparisons' . DS . 'Controller' . DS; @@ -63,7 +63,7 @@ public function setUp(): void * * @return void */ - public function tearDown(): void + protected function tearDown(): void { parent::tearDown(); $this->getTableLocator()->clear(); @@ -74,7 +74,7 @@ public function tearDown(): void * * @return void */ - public function testExecute() + public function testExecute(): void { foreach ($this->tables as $table) { $plural = Inflector::camelize($table); diff --git a/tests/TestCase/Command/ControllerCommandTest.php b/tests/TestCase/Command/ControllerCommandTest.php index 00e73762..2c673157 100644 --- a/tests/TestCase/Command/ControllerCommandTest.php +++ b/tests/TestCase/Command/ControllerCommandTest.php @@ -48,7 +48,7 @@ class ControllerCommandTest extends TestCase * * @return void */ - public function setUp(): void + protected function setUp(): void { parent::setUp(); $this->_compareBasePath = Plugin::path('Bake') . 'tests' . DS . 'comparisons' . DS . 'Controller' . DS; @@ -64,7 +64,7 @@ public function setUp(): void * * @return void */ - public function tearDown(): void + protected function tearDown(): void { parent::tearDown(); $this->getTableLocator()->clear(); @@ -77,7 +77,7 @@ public function tearDown(): void * * @return void */ - public function testMainListAvailable() + public function testMainListAvailable(): void { $this->exec('bake controller'); @@ -93,7 +93,7 @@ public function testMainListAvailable() * * @return void */ - public function testGetComponents() + public function testGetComponents(): void { $command = new ControllerCommand(); $args = new Arguments([], [], []); @@ -110,7 +110,7 @@ public function testGetComponents() * * @return void */ - public function testGetComponentsInferredDefaults() + public function testGetComponentsInferredDefaults(): void { $this->_loadTestPlugin('Authorization'); @@ -129,7 +129,7 @@ public function testGetComponentsInferredDefaults() * * @return void */ - public function testGetHelpers() + public function testGetHelpers(): void { $command = new ControllerCommand(); $args = new Arguments([], [], []); @@ -146,7 +146,7 @@ public function testGetHelpers() * * @return void */ - public function testBakeComponents() + public function testBakeComponents(): void { $this->generatedFile = APP . 'Controller/BakeArticlesController.php'; $this->exec( @@ -165,7 +165,7 @@ public function testBakeComponents() * * @return void */ - public function testBakeActionsOption() + public function testBakeActionsOption(): void { $this->generatedFile = APP . 'Controller/BakeArticlesController.php'; $this->exec( @@ -184,7 +184,7 @@ public function testBakeActionsOption() * * @return void */ - public function testBakeNoActions() + public function testBakeNoActions(): void { $this->generatedFile = APP . 'Controller/BakeArticlesController.php'; $this->exec( @@ -202,7 +202,7 @@ public function testBakeNoActions() * * @return void */ - public function testBakeActions() + public function testBakeActions(): void { $this->generatedFile = APP . 'Controller/BakeArticlesController.php'; $this->exec( @@ -218,7 +218,7 @@ public function testBakeActions() /** * Test the integration with Authorization plugin */ - public function testBakeActionsAuthorizationPlugin() + public function testBakeActionsAuthorizationPlugin(): void { $this->_loadTestPlugin('Authorization'); @@ -233,7 +233,7 @@ public function testBakeActionsAuthorizationPlugin() /** * Test the integration with Authentication plugin */ - public function testBakeActionsAuthenticationPlugin() + public function testBakeActionsAuthenticationPlugin(): void { $this->_loadTestPlugin('Authentication'); @@ -257,7 +257,7 @@ public function testBakeActionsAuthenticationPlugin() * * @return void */ - public function testBakePrefixed() + public function testBakePrefixed(): void { $this->generatedFile = APP . 'Controller/Admin/BakeArticlesController.php'; $this->exec('bake controller --connection test --no-test --prefix admin BakeArticles'); @@ -272,7 +272,7 @@ public function testBakePrefixed() * * @return void */ - public function testBakePrefixNested() + public function testBakePrefixNested(): void { $this->generatedFile = APP . 'Controller/Admin/Management/BakeArticlesController.php'; $this->exec('bake controller --connection test --no-test --prefix admin/management BakeArticles'); @@ -287,7 +287,7 @@ public function testBakePrefixNested() * * @return void */ - public function testBakeWithPlugin() + public function testBakeWithPlugin(): void { $this->_loadTestPlugin('BakeTest'); $path = Plugin::path('BakeTest'); @@ -304,7 +304,7 @@ public function testBakeWithPlugin() * * @return void */ - public function testBakeActionsContent() + public function testBakeActionsContent(): void { $this->generatedFile = APP . 'Controller/BakeArticlesController.php'; $this->exec('bake controller --connection test --no-test BakeArticles'); @@ -318,7 +318,7 @@ public function testBakeActionsContent() * * @return void */ - public function testBakeTest() + public function testBakeTest(): void { $this->generatedFiles = [ APP . 'Controller/BakeArticlesController.php', @@ -343,7 +343,7 @@ public function testBakeTest() * * @return void */ - public function testBakeTestDisabled() + public function testBakeTestDisabled(): void { $this->generatedFile = APP . 'Controller/BakeArticlesController.php'; $this->exec('bake controller --connection test --no-test BakeArticles'); @@ -358,7 +358,7 @@ public function testBakeTestDisabled() * * @return void */ - public function testMainNoArgs() + public function testMainNoArgs(): void { $this->exec('bake controller'); @@ -372,7 +372,7 @@ public function testMainNoArgs() * * @return void */ - public static function nameVariations() + public static function nameVariations(): array { return [ ['BakeArticles'], ['bake_articles'], @@ -385,7 +385,7 @@ public static function nameVariations() * @return void */ #[DataProvider('nameVariations')] - public function testMainWithControllerNameVariations($name) + public function testMainWithControllerNameVariations(string $name): void { $this->generatedFile = APP . 'Controller/BakeArticlesController.php'; $this->exec("bake controller --connection test --no-test {$name}"); @@ -400,7 +400,7 @@ public function testMainWithControllerNameVariations($name) * * @return void */ - public function testMainWithPluginDot() + public function testMainWithPluginDot(): void { $this->_loadTestPlugin('Company/Pastry'); $path = Plugin::path('Company/Pastry'); @@ -421,7 +421,7 @@ public function testMainWithPluginDot() * * @return void */ - public function testMainWithPluginOption() + public function testMainWithPluginOption(): void { $this->_loadTestPlugin('Company/Pastry'); $path = Plugin::path('Company/Pastry'); diff --git a/tests/TestCase/Command/EntryCommandTest.php b/tests/TestCase/Command/EntryCommandTest.php index 346fbe3f..712582b3 100644 --- a/tests/TestCase/Command/EntryCommandTest.php +++ b/tests/TestCase/Command/EntryCommandTest.php @@ -29,7 +29,7 @@ class EntryCommandTest extends TestCase * * @return void */ - public function setUp(): void + protected function setUp(): void { parent::setUp(); @@ -41,7 +41,7 @@ public function setUp(): void * * @return void */ - public function tearDown(): void + protected function tearDown(): void { parent::tearDown(); $this->removePlugins(['BakeTest']); @@ -52,7 +52,7 @@ public function tearDown(): void * * @return void */ - public function testExecuteHelp() + public function testExecuteHelp(): void { $this->exec('bake --help'); @@ -74,7 +74,7 @@ public function testExecuteHelp() * * @return void */ - public function testExecuteAppCommand() + public function testExecuteAppCommand(): void { $this->exec('bake app_policy'); $this->assertExitCode(CommandInterface::CODE_SUCCESS); @@ -86,7 +86,7 @@ public function testExecuteAppCommand() * * @return void */ - public function testExecuteAppTaskHelp() + public function testExecuteAppTaskHelp(): void { $this->exec('bake app_policy --help'); @@ -100,7 +100,7 @@ public function testExecuteAppTaskHelp() * * @return void */ - public function testExecutePluginCommand() + public function testExecutePluginCommand(): void { $this->_loadTestPlugin('BakeTest'); @@ -116,7 +116,7 @@ public function testExecutePluginCommand() * * @return void */ - public function testExecuteMissingCommand() + public function testExecuteMissingCommand(): void { $this->exec('bake nope'); diff --git a/tests/TestCase/Command/EnumCommandTest.php b/tests/TestCase/Command/EnumCommandTest.php index bc34dcb1..d7849669 100644 --- a/tests/TestCase/Command/EnumCommandTest.php +++ b/tests/TestCase/Command/EnumCommandTest.php @@ -30,7 +30,7 @@ class EnumCommandTest extends TestCase * * @return void */ - public function setUp(): void + protected function setUp(): void { parent::setUp(); $this->_compareBasePath = Plugin::path('Bake') . 'tests' . DS . 'comparisons' . DS . 'Model' . DS; @@ -42,7 +42,7 @@ public function setUp(): void * * @return void */ - public function testBakeEnum() + public function testBakeEnum(): void { $this->generatedFile = APP . 'Model/Enum/FooBar.php'; $this->exec('bake enum FooBar', ['y']); @@ -58,7 +58,7 @@ public function testBakeEnum() * * @return void */ - public function testBakeEnumBackedInt() + public function testBakeEnumBackedInt(): void { $this->generatedFile = APP . 'Model/Enum/FooBar.php'; $this->exec('bake enum FooBar -i', ['y']); @@ -74,7 +74,7 @@ public function testBakeEnumBackedInt() * * @return void */ - public function testBakeEnumBackedWithCases() + public function testBakeEnumBackedWithCases(): void { $this->generatedFile = APP . 'Model/Enum/FooBar.php'; $this->exec('bake enum FooBar foo,bar:b,bar_baz', ['y']); @@ -90,7 +90,7 @@ public function testBakeEnumBackedWithCases() * * @return void */ - public function testBakeEnumBackedIntWithCases() + public function testBakeEnumBackedIntWithCases(): void { $this->generatedFile = APP . 'Model/Enum/FooBar.php'; $this->exec('bake enum FooBar foo,bar,bar_baz:9 -i', ['y']); diff --git a/tests/TestCase/Command/FixtureAllCommandTest.php b/tests/TestCase/Command/FixtureAllCommandTest.php index 735eba07..0544a1d7 100644 --- a/tests/TestCase/Command/FixtureAllCommandTest.php +++ b/tests/TestCase/Command/FixtureAllCommandTest.php @@ -47,7 +47,7 @@ class FixtureAllCommandTest extends TestCase * * @return void */ - public function setUp(): void + protected function setUp(): void { parent::setUp(); @@ -64,7 +64,7 @@ public function setUp(): void * * @return void */ - public function tearDown(): void + protected function tearDown(): void { parent::tearDown(); $connection = ConnectionManager::get('test'); @@ -76,7 +76,7 @@ public function tearDown(): void * * @return void */ - public function testMainIntoAll() + public function testMainIntoAll(): void { $this->generatedFiles = [ ROOT . 'tests/Fixture/ArticlesFixture.php', @@ -95,7 +95,7 @@ public function testMainIntoAll() * * @return void */ - public function testAllWithCountAndRecordsFlags() + public function testAllWithCountAndRecordsFlags(): void { $this->generatedFiles = [ ROOT . 'tests/Fixture/ArticlesFixture.php', @@ -117,7 +117,7 @@ public function testAllWithCountAndRecordsFlags() * * @return void */ - public function testAllWithSchemaImport() + public function testAllWithSchemaImport(): void { $this->generatedFiles = [ ROOT . 'tests/Fixture/ArticlesFixture.php', diff --git a/tests/TestCase/Command/FixtureCommandTest.php b/tests/TestCase/Command/FixtureCommandTest.php index a265731b..866ab4fc 100644 --- a/tests/TestCase/Command/FixtureCommandTest.php +++ b/tests/TestCase/Command/FixtureCommandTest.php @@ -51,7 +51,7 @@ class FixtureCommandTest extends TestCase * * @return void */ - public function setUp(): void + protected function setUp(): void { parent::setUp(); @@ -117,7 +117,7 @@ public function testValidateNamesWithInvalidSpecialChars(): void * * @return void */ - public function testImportRecordsFromDatabase() + public function testImportRecordsFromDatabase(): void { $this->generatedFile = ROOT . 'tests/Fixture/DatatypesFixture.php'; $this->exec('bake fixture --connection test --schema --records --count 2 Datatypes'); @@ -134,7 +134,7 @@ public function testImportRecordsFromDatabase() * * @return void */ - public function testImportOptionsAlternateConnection() + public function testImportOptionsAlternateConnection(): void { $this->generatedFile = ROOT . 'tests/Fixture/ArticleFixture.php'; $this->exec('bake fixture --connection test --schema Article'); @@ -148,7 +148,7 @@ public function testImportOptionsAlternateConnection() * * @return void */ - public function testImportRecordsNoEscaping() + public function testImportRecordsNoEscaping(): void { $articles = $this->getTableLocator()->get('Articles'); $articles->updateAll(['body' => 'Body "value"'], []); @@ -169,7 +169,7 @@ public function testImportRecordsNoEscaping() * * @return void */ - public function testMainWithTableOption() + public function testMainWithTableOption(): void { $this->generatedFile = ROOT . 'tests/Fixture/ArticlesFixture.php'; $this->exec('bake fixture --connection test --table comments Articles'); @@ -183,7 +183,7 @@ public function testMainWithTableOption() * * @return void */ - public function testMainWithSingularTable() + public function testMainWithSingularTable(): void { $this->generatedFile = ROOT . 'tests/Fixture/CarFixture.php'; $this->exec('bake fixture --connection test car'); @@ -198,7 +198,7 @@ public function testMainWithSingularTable() * * @return void */ - public function testMainWithPluginModel() + public function testMainWithPluginModel(): void { $this->loadPlugins(['FixtureTest' => ['path' => APP . 'Plugin/FixtureTest/']]); @@ -214,7 +214,7 @@ public function testMainWithPluginModel() * * @return void */ - public function testMainNoArgs() + public function testMainNoArgs(): void { $this->exec('bake fixture --connection test'); @@ -228,7 +228,7 @@ public function testMainNoArgs() * * @return void */ - public function testBake() + public function testBake(): void { $this->generatedFile = ROOT . 'tests/Fixture/ArticlesFixture.php'; $this->exec('bake fixture --connection test --fields Articles'); @@ -244,7 +244,7 @@ public function testBake() * * @return void */ - public function testBakeNoFields() + public function testBakeNoFields(): void { $this->generatedFile = ROOT . 'tests/Fixture/ArticlesFixture.php'; $this->exec('bake fixture --connection test Articles'); @@ -261,7 +261,7 @@ public function testBakeNoFields() * * @return void */ - public function testMainImportSchema() + public function testMainImportSchema(): void { $this->generatedFile = ROOT . 'tests/Fixture/CommentsFixture.php'; $this->exec('bake fixture --connection test --schema Comments'); @@ -277,7 +277,7 @@ public function testMainImportSchema() * * @return void */ - public function testRecordGenerationForDatatypes() + public function testRecordGenerationForDatatypes(): void { $this->generatedFile = ROOT . 'tests/Fixture/DatatypesFixture.php'; $this->exec('bake fixture --connection test --fields Datatypes'); @@ -305,7 +305,7 @@ public function testRecordGenerationForDatatypes() * * @return void */ - public function testRecordGenerationForBinaryType() + public function testRecordGenerationForBinaryType(): void { $driver = ConnectionManager::get('test')->getDriver(); $this->skipIf($driver instanceof Postgres, 'Incompatible with postgres'); @@ -322,7 +322,7 @@ public function testRecordGenerationForBinaryType() * * @return void */ - public function testRecordGenerationForBinaryTypePostgres() + public function testRecordGenerationForBinaryTypePostgres(): void { $driver = ConnectionManager::get('test')->getDriver(); $this->skipIf(($driver instanceof Postgres) === false, 'Only compatible with postgres'); @@ -339,7 +339,7 @@ public function testRecordGenerationForBinaryTypePostgres() * * @return void */ - public function testGenerateFixtureFileRemappedJsonTypes() + public function testGenerateFixtureFileRemappedJsonTypes(): void { $table = $this->getTableLocator()->get('Articles'); $table->getSchema()->addColumn('body', ['type' => 'json']); @@ -356,7 +356,7 @@ public function testGenerateFixtureFileRemappedJsonTypes() * * @return void */ - public function testGeneratePluginFixtureFile() + public function testGeneratePluginFixtureFile(): void { $this->_loadTestPlugin('TestBake'); $root = Plugin::path('TestBake'); diff --git a/tests/TestCase/Command/FormCommandTest.php b/tests/TestCase/Command/FormCommandTest.php index d78395bd..cf642614 100644 --- a/tests/TestCase/Command/FormCommandTest.php +++ b/tests/TestCase/Command/FormCommandTest.php @@ -29,7 +29,7 @@ class FormCommandTest extends TestCase * * @return void */ - public function setUp(): void + protected function setUp(): void { parent::setUp(); @@ -41,7 +41,7 @@ public function setUp(): void * * @return void */ - public function testCommand() + public function testCommand(): void { $this->generatedFiles = [ APP . 'Form' . DS . 'TestForm.php', diff --git a/tests/TestCase/Command/MailerCommandTest.php b/tests/TestCase/Command/MailerCommandTest.php index 58e0b6f7..dd11c2d2 100644 --- a/tests/TestCase/Command/MailerCommandTest.php +++ b/tests/TestCase/Command/MailerCommandTest.php @@ -30,7 +30,7 @@ class MailerCommandTest extends TestCase * * @return void */ - public function setUp(): void + protected function setUp(): void { parent::setUp(); $this->_compareBasePath = Plugin::path('Bake') . 'tests' . DS . 'comparisons' . DS . 'Mailer' . DS; @@ -42,7 +42,7 @@ public function setUp(): void * * @return void */ - public function testMain() + public function testMain(): void { $this->generatedFiles = [ APP . 'Mailer/ExampleMailer.php', @@ -60,7 +60,7 @@ public function testMain() * * @return void */ - public function testMainPlugin() + public function testMainPlugin(): void { $this->_loadTestPlugin('TestBake'); $path = Plugin::path('TestBake'); @@ -82,7 +82,7 @@ public function testMainPlugin() * * @return void */ - public function testBakePlugin() + public function testBakePlugin(): void { $this->_loadTestPlugin('TestBake'); $path = Plugin::path('TestBake'); diff --git a/tests/TestCase/Command/MiddlewareCommandTest.php b/tests/TestCase/Command/MiddlewareCommandTest.php index 4a79ce13..afd49bef 100644 --- a/tests/TestCase/Command/MiddlewareCommandTest.php +++ b/tests/TestCase/Command/MiddlewareCommandTest.php @@ -30,7 +30,7 @@ class MiddlewareCommandTest extends TestCase * * @return void */ - public function setUp(): void + protected function setUp(): void { parent::setUp(); $this->_compareBasePath = Plugin::path('Bake') . 'tests' . DS . 'comparisons' . DS . 'Middleware' . DS; @@ -42,7 +42,7 @@ public function setUp(): void * * @return void */ - public function testMain() + public function testMain(): void { $this->generatedFile = APP . 'Middleware/ExampleMiddleware.php'; $this->exec('bake middleware example', ['y']); @@ -56,7 +56,7 @@ public function testMain() * * @return void */ - public function testMainPlugin() + public function testMainPlugin(): void { $this->_loadTestPlugin('TestBake'); $path = Plugin::path('TestBake'); @@ -73,7 +73,7 @@ public function testMainPlugin() * * @return void */ - public function testBakePlugin() + public function testBakePlugin(): void { $this->_loadTestPlugin('TestBake'); $path = Plugin::path('TestBake'); diff --git a/tests/TestCase/Command/ModelAllCommandTest.php b/tests/TestCase/Command/ModelAllCommandTest.php index 768428dc..59bb054f 100644 --- a/tests/TestCase/Command/ModelAllCommandTest.php +++ b/tests/TestCase/Command/ModelAllCommandTest.php @@ -47,7 +47,7 @@ class ModelAllCommandTest extends TestCase * * @return void */ - public function setUp(): void + protected function setUp(): void { parent::setUp(); $this->setAppNamespace('Bake\Test\App'); @@ -62,7 +62,7 @@ public function setUp(): void * * @return void */ - public function tearDown(): void + protected function tearDown(): void { parent::tearDown(); $connection = ConnectionManager::get('test'); @@ -76,7 +76,7 @@ public function tearDown(): void * * @return void */ - public function testExecute() + public function testExecute(): void { foreach ($this->tables as $table) { $plural = Inflector::camelize($table); diff --git a/tests/TestCase/Command/ModelCommandAssociationDetectionTest.php b/tests/TestCase/Command/ModelCommandAssociationDetectionTest.php index 80558cc8..5e30da66 100644 --- a/tests/TestCase/Command/ModelCommandAssociationDetectionTest.php +++ b/tests/TestCase/Command/ModelCommandAssociationDetectionTest.php @@ -51,7 +51,7 @@ class ModelCommandAssociationDetectionTest extends TestCase * * @return void */ - public function setUp(): void + protected function setUp(): void { parent::setUp(); $this->_compareBasePath = Plugin::path('Bake') . 'tests' . DS . 'comparisons' . DS . 'Model' . DS; @@ -65,7 +65,7 @@ public function setUp(): void * * @return void */ - public function tearDown(): void + protected function tearDown(): void { parent::tearDown(); $this->getTableLocator()->clear(); @@ -76,7 +76,7 @@ public function tearDown(): void * * @return void */ - protected function _compareBakeTableResult($name, $comparisonFile) + protected function _compareBakeTableResult($name, string $comparisonFile) { $this->generatedFiles = [ APP . "Model/Table/{$name}Table.php", @@ -93,7 +93,7 @@ protected function _compareBakeTableResult($name, $comparisonFile) * * @return void */ - public function testBakeAssociationDetectionCategoriesTable() + public function testBakeAssociationDetectionCategoriesTable(): void { $driver = ConnectionManager::get('test')->getDriver(); $this->skipIf($driver instanceof Mysql, 'Incompatible with mysql'); @@ -105,7 +105,7 @@ public function testBakeAssociationDetectionCategoriesTable() * * @return void */ - public function testBakeAssociationDetectionCategoriesTableSigned() + public function testBakeAssociationDetectionCategoriesTableSigned(): void { $driver = ConnectionManager::get('test')->getDriver(); $this->skipIf($driver instanceof Sqlite, 'Incompatible with sqlite'); @@ -119,7 +119,7 @@ public function testBakeAssociationDetectionCategoriesTableSigned() * * @return void */ - public function testBakeAssociationDetectionCategoriesProductsTable() + public function testBakeAssociationDetectionCategoriesProductsTable(): void { $this->_compareBakeTableResult('CategoriesProducts', __FUNCTION__); } @@ -129,7 +129,7 @@ public function testBakeAssociationDetectionCategoriesProductsTable() * * @return void */ - public function testBakeAssociationDetectionOldProductsTable() + public function testBakeAssociationDetectionOldProductsTable(): void { $driver = ConnectionManager::get('test')->getDriver(); $this->skipIf($driver instanceof Mysql, 'Incompatible with mysql'); @@ -141,7 +141,7 @@ public function testBakeAssociationDetectionOldProductsTable() * * @return void */ - public function testBakeAssociationDetectionOldProductsTableSigned() + public function testBakeAssociationDetectionOldProductsTableSigned(): void { $driver = ConnectionManager::get('test')->getDriver(); $this->skipIf($driver instanceof Sqlite, 'Incompatible with sqlite'); @@ -155,7 +155,7 @@ public function testBakeAssociationDetectionOldProductsTableSigned() * * @return void */ - public function testBakeAssociationDetectionProductVersionsTable() + public function testBakeAssociationDetectionProductVersionsTable(): void { $driver = ConnectionManager::get('test')->getDriver(); $this->skipIf($driver instanceof Mysql, 'Incompatible with mysql'); @@ -168,7 +168,7 @@ public function testBakeAssociationDetectionProductVersionsTable() * * @return void */ - public function testBakeAssociationDetectionProductVersionsTableSigned() + public function testBakeAssociationDetectionProductVersionsTableSigned(): void { $driver = ConnectionManager::get('test')->getDriver(); $this->skipIf($driver instanceof Postgres, 'Incompatible with postgres'); diff --git a/tests/TestCase/Command/ModelCommandTest.php b/tests/TestCase/Command/ModelCommandTest.php index 0afceb9a..8870892b 100644 --- a/tests/TestCase/Command/ModelCommandTest.php +++ b/tests/TestCase/Command/ModelCommandTest.php @@ -68,7 +68,7 @@ class ModelCommandTest extends TestCase * * @return void */ - public function setUp(): void + protected function setUp(): void { parent::setUp(); $this->_compareBasePath = Plugin::path('Bake') . 'tests' . DS . 'comparisons' . DS . 'Model' . DS; @@ -82,7 +82,7 @@ public function setUp(): void * * @return void */ - public function tearDown(): void + protected function tearDown(): void { parent::tearDown(); $this->getTableLocator()->clear(); @@ -93,7 +93,7 @@ public function tearDown(): void * * @return void */ - public function testListAllConnection() + public function testListAllConnection(): void { $this->exec('bake model --connection test'); @@ -110,7 +110,7 @@ public function testListAllConnection() * * @return void */ - public function testGetTable() + public function testGetTable(): void { $command = new ModelCommand(); $args = new Arguments([], [], []); @@ -127,7 +127,7 @@ public function testGetTable() * * @return void */ - public function testGetTableObject() + public function testGetTableObject(): void { $command = new ModelCommand(); $command->connection = 'test'; @@ -147,7 +147,7 @@ public function testGetTableObject() * * @return void */ - public function testGetTableObjectPrefix() + public function testGetTableObjectPrefix(): void { $command = new ModelCommand(); $command->connection = 'test'; @@ -206,7 +206,7 @@ public function testValidateNamesWithInvalid(): void * * @return void */ - public function testApplyAssociations() + public function testApplyAssociations(): void { $articles = $this->getTableLocator()->get('TodoItems'); $assocs = [ @@ -248,7 +248,7 @@ public function testApplyAssociations() * * @return void */ - public function testApplyAssociationsConcreteClass() + public function testApplyAssociationsConcreteClass(): void { Configure::write('App.namespace', 'Bake\Test\App'); $articles = $this->getTableLocator()->get('Articles'); @@ -287,7 +287,7 @@ public function testApplyAssociationsConcreteClass() * * @return void */ - public function testGetAssociations() + public function testGetAssociations(): void { $items = $this->getTableLocator()->get('TodoItems'); @@ -335,7 +335,7 @@ public function testGetAssociations() * * @return void */ - public function testGetAssociationsNoFlag() + public function testGetAssociationsNoFlag(): void { $command = new ModelCommand(); $command->connection = 'test'; @@ -351,7 +351,7 @@ public function testGetAssociationsNoFlag() * * @return void */ - public function testGetAssociationsPlugin() + public function testGetAssociationsPlugin(): void { $items = $this->getTableLocator()->get('TodoItems'); $command = new ModelCommand(); @@ -403,7 +403,7 @@ public function testGetAssociationsPlugin() * * @return void */ - public function testGetAssociationsIgnoreUnderscoreIdIfNoDbTable() + public function testGetAssociationsIgnoreUnderscoreIdIfNoDbTable(): void { $items = $this->getTableLocator()->get('TodoItems'); @@ -452,7 +452,7 @@ public function testGetAssociationsIgnoreUnderscoreIdIfNoDbTable() * * @return void */ - public function testGetAssociationsAddAssociationIfTableExist() + public function testGetAssociationsAddAssociationIfTableExist(): void { $items = $this->getTableLocator()->get('TodoItems'); @@ -505,7 +505,7 @@ public function testGetAssociationsAddAssociationIfTableExist() * * @return void */ - public function testGetAssociationsAddAssociationIfNoTableExistButAliasIsAllowed() + public function testGetAssociationsAddAssociationIfNoTableExistButAliasIsAllowed(): void { $items = $this->getTableLocator()->get('TodoItems'); @@ -557,7 +557,7 @@ public function testGetAssociationsAddAssociationIfNoTableExistButAliasIsAllowed * * @return void */ - public function testGetAssociationsIgnoreUnderscoreId() + public function testGetAssociationsIgnoreUnderscoreId(): void { $model = $this->getTableLocator()->get('BakeComments'); $model->setSchema([ @@ -585,7 +585,7 @@ public function testGetAssociationsIgnoreUnderscoreId() * * @return void */ - public function testGetAssociationsConstraints() + public function testGetAssociationsConstraints(): void { $model = $this->getTableLocator()->get('Invitations'); $command = new ModelCommand(); @@ -617,7 +617,7 @@ public function testGetAssociationsConstraints() * * @return void */ - public function testBelongsToGeneration() + public function testBelongsToGeneration(): void { $model = $this->getTableLocator()->get('TodoItems'); $command = new ModelCommand(); @@ -667,7 +667,7 @@ public function testBelongsToGeneration() * * @return void */ - public function testBelongsToGenerationConstraints() + public function testBelongsToGenerationConstraints(): void { $model = $this->getTableLocator()->get('Relations'); $command = new ModelCommand(); @@ -696,7 +696,7 @@ public function testBelongsToGenerationConstraints() * * @return void */ - public function testBelongsToGenerationConstraintsAliased() + public function testBelongsToGenerationConstraintsAliased(): void { $model = $this->getTableLocator()->get('Invitations'); $command = new ModelCommand(); @@ -727,7 +727,7 @@ public function testBelongsToGenerationConstraintsAliased() * * @return void */ - public function testBelongsToGenerationCompositeKey() + public function testBelongsToGenerationCompositeKey(): void { $model = $this->getTableLocator()->get('TodoItemsTodoLabels'); $command = new ModelCommand(); @@ -755,7 +755,7 @@ public function testBelongsToGenerationCompositeKey() * * @return void */ - public function testBelongsToGenerationIdMidColumn() + public function testBelongsToGenerationIdMidColumn(): void { $model = $this->getTableLocator()->get('TodoItems'); $model->setSchema([ @@ -772,7 +772,7 @@ public function testBelongsToGenerationIdMidColumn() * * @return void */ - public function testBelongsToGenerationPrimaryKey() + public function testBelongsToGenerationPrimaryKey(): void { $model = $this->getTableLocator()->get('Articles'); $model->setSchema([ @@ -792,7 +792,7 @@ public function testBelongsToGenerationPrimaryKey() * * @return void */ - public function testHasOneGeneration() + public function testHasOneGeneration(): void { $command = new ModelCommand(); $command->connection = 'test'; @@ -819,7 +819,7 @@ public function testHasOneGeneration() * * @return void */ - public function testHasManyGeneration() + public function testHasManyGeneration(): void { $command = new ModelCommand(); $command->connection = 'test'; @@ -885,7 +885,7 @@ public function testHasManyGeneration() * * @return void */ - public function testHasAndBelongsToManyGeneration() + public function testHasAndBelongsToManyGeneration(): void { $command = new ModelCommand(); $command->connection = 'test'; @@ -909,7 +909,7 @@ public function testHasAndBelongsToManyGeneration() * * @return void */ - public function testGetEntityPropertySchema() + public function testGetEntityPropertySchema(): void { $model = $this->getTableLocator()->get('TodoItems'); $model->belongsTo('BakeUsers'); @@ -996,7 +996,7 @@ public function testGetEntityPropertySchema() * * @return void */ - public function testGetFields() + public function testGetFields(): void { $model = $this->getTableLocator()->get('TodoItems'); @@ -1020,7 +1020,7 @@ public function testGetFields() * * @return void */ - public function testGetFieldsDisabled() + public function testGetFieldsDisabled(): void { $model = $this->getTableLocator()->get('TodoItems'); $args = new Arguments([], ['no-fields' => true], []); @@ -1034,7 +1034,7 @@ public function testGetFieldsDisabled() * * @return void */ - public function testGetFieldsWhiteList() + public function testGetFieldsWhiteList(): void { $model = $this->getTableLocator()->get('TodoItems'); @@ -1055,7 +1055,7 @@ public function testGetFieldsWhiteList() * * @return void */ - public function testGetHiddenFields() + public function testGetHiddenFields(): void { $model = $this->getTableLocator()->get('Users'); @@ -1073,7 +1073,7 @@ public function testGetHiddenFields() * * @return void */ - public function testGetHiddenFieldsDisabled() + public function testGetHiddenFieldsDisabled(): void { $model = $this->getTableLocator()->get('Users'); @@ -1088,7 +1088,7 @@ public function testGetHiddenFieldsDisabled() * * @return void */ - public function testGetHiddenFieldsWhiteList() + public function testGetHiddenFieldsWhiteList(): void { $model = $this->getTableLocator()->get('Users'); @@ -1109,7 +1109,7 @@ public function testGetHiddenFieldsWhiteList() * * @return void */ - public function testGetPrimaryKey() + public function testGetPrimaryKey(): void { $model = $this->getTableLocator()->get('TodoItems'); $command = new ModelCommand(); @@ -1130,7 +1130,7 @@ public function testGetPrimaryKey() * * @return void */ - public function testGetValidationDisabled() + public function testGetValidationDisabled(): void { $model = $this->getTableLocator()->get('TodoItems'); $command = new ModelCommand(); @@ -1144,7 +1144,7 @@ public function testGetValidationDisabled() * * @return void */ - public function testGetValidation() + public function testGetValidation(): void { $driver = ConnectionManager::get('test')->getDriver(); $this->skipIf($driver instanceof Postgres, 'Incompatible with postgres'); @@ -1192,7 +1192,7 @@ public function testGetValidation() * * @return void */ - public function testGetValidationSigned() + public function testGetValidationSigned(): void { $driver = ConnectionManager::get('test')->getDriver(); $this->skipIf($driver instanceof Sqlite, 'Incompatible with sqlite'); @@ -1235,7 +1235,7 @@ public function testGetValidationSigned() * * @return void */ - public function testGetValidationUniqueDateField() + public function testGetValidationUniqueDateField(): void { $model = $this->getTableLocator()->get('TodoItems'); $schema = $model->getSchema(); @@ -1263,7 +1263,7 @@ public function testGetValidationUniqueDateField() * * @return void */ - public function testGetValidationTree() + public function testGetValidationTree(): void { $driver = ConnectionManager::get('test')->getDriver(); $this->skipIf($driver instanceof Postgres, 'Incompatible with postgres'); @@ -1297,7 +1297,7 @@ public function testGetValidationTree() * * @return void */ - public function testGetValidationTreeSigned() + public function testGetValidationTreeSigned(): void { $driver = ConnectionManager::get('test')->getDriver(); $this->skipIf($driver instanceof Sqlite, 'Incompatible with sqlite'); @@ -1331,7 +1331,7 @@ public function testGetValidationTreeSigned() * * @return void */ - public function testGetValidationExcludeForeignKeysSigned() + public function testGetValidationExcludeForeignKeysSigned(): void { $driver = ConnectionManager::get('test')->getDriver(); $this->skipIf($driver instanceof Sqlite, 'Incompatible with sqlite'); @@ -1467,7 +1467,7 @@ public function testGetValidationOfPossibleFileFields(): void * * @return void */ - public function testGetRulesDisabled() + public function testGetRulesDisabled(): void { $model = $this->getTableLocator()->get('Users'); $command = new ModelCommand(); @@ -1481,7 +1481,7 @@ public function testGetRulesDisabled() * * @return void */ - public function testGetRules() + public function testGetRules(): void { $model = $this->getTableLocator()->get('Users'); $associations = [ @@ -1532,7 +1532,7 @@ public function testGetRules() * * @return void */ - public function testGetRulesUniqueKeys() + public function testGetRulesUniqueKeys(): void { $model = $this->getTableLocator()->get('TodoItems'); $model->getSchema()->addConstraint('unique_title', [ @@ -1689,7 +1689,7 @@ public function testGetRulesForPossiblyUniqueColumns(): void * * @return void */ - public function testGetBehaviorsAutoDetect() + public function testGetBehaviorsAutoDetect(): void { $command = new ModelCommand(); $command->connection = 'test'; @@ -1708,7 +1708,7 @@ public function testGetBehaviorsAutoDetect() * * @return void */ - public function testGetDisplayField() + public function testGetDisplayField(): void { $model = $this->getTableLocator()->get('TodoItems'); $command = new ModelCommand(); @@ -1726,7 +1726,7 @@ public function testGetDisplayField() * * @return void */ - public function testBakeFixture() + public function testBakeFixture(): void { $this->generatedFiles = [ APP . 'Model/Table/TodoItemsTable.php', @@ -1745,7 +1745,7 @@ public function testBakeFixture() * * @return void */ - public function testBakeFixtureDisabled() + public function testBakeFixtureDisabled(): void { $this->generatedFiles = [ APP . 'Model/Table/TodoItemsTable.php', @@ -1764,7 +1764,7 @@ public function testBakeFixtureDisabled() * * @return void */ - public function testBakeTest() + public function testBakeTest(): void { $this->generatedFiles = [ APP . 'Model/Table/TodoItemsTable.php', @@ -1783,7 +1783,7 @@ public function testBakeTest() * * @return void */ - public function testBakeTableValidation() + public function testBakeTableValidation(): void { $this->generatedFiles = [ APP . 'Model/Table/TestBakeArticlesTable.php', @@ -1940,7 +1940,7 @@ public function testBakeTableRules(): void * * @return void */ - public function testBakeTableConfig() + public function testBakeTableConfig(): void { $this->generatedFiles = [ APP . 'Model/Table/ItemsTable.php', @@ -1959,7 +1959,7 @@ public function testBakeTableConfig() * * @return void */ - public function testBakeEntitySimple() + public function testBakeEntitySimple(): void { $this->generatedFile = APP . 'Model/Entity/User.php'; $this->exec('bake model --no-test --no-fixture --no-table --no-fields --no-hidden users'); @@ -1995,7 +1995,7 @@ public function testBakeEntitySimpleUnchanged(): void * * @return void */ - public function testBakeEntityFullContext() + public function testBakeEntityFullContext(): void { $this->generatedFile = APP . 'Model/Entity/User.php'; $this->exec('bake model --no-test --no-fixture --no-table users'); @@ -2011,7 +2011,7 @@ public function testBakeEntityFullContext() * * @return void */ - public function testBakeEntityWithPropertyTypeHints() + public function testBakeEntityWithPropertyTypeHints(): void { $model = $this->getTableLocator()->get('TodoItems'); $model->associations()->removeAll(); @@ -2045,7 +2045,7 @@ public function testBakeEntityWithPropertyTypeHints() * * @return void */ - public function testBakeEntityFieldsDefaults() + public function testBakeEntityFieldsDefaults(): void { $this->generatedFiles = [ APP . 'Model/Entity/TodoItem.php', @@ -2063,7 +2063,7 @@ public function testBakeEntityFieldsDefaults() * * @return void */ - public function testBakeEntityNoFields() + public function testBakeEntityNoFields(): void { $this->generatedFile = APP . 'Model/Entity/TodoItem.php'; $this->exec('bake model --no-test --no-fixture --no-table --no-fields todo_items'); @@ -2079,7 +2079,7 @@ public function testBakeEntityNoFields() * * @return void */ - public function testBakeEntityFieldsWhiteList() + public function testBakeEntityFieldsWhiteList(): void { $this->generatedFile = APP . 'Model/Entity/TodoItem.php'; $this->exec('bake model --no-test --no-fixture --no-table --fields id,title,body,completed todo_items'); @@ -2095,7 +2095,7 @@ public function testBakeEntityFieldsWhiteList() * * @return void */ - public function testBakeEntityHidden() + public function testBakeEntityHidden(): void { $this->generatedFile = APP . 'Model/Entity/User.php'; $this->exec('bake model --no-test --no-fixture --no-table --no-fields --hidden password users'); @@ -2111,7 +2111,7 @@ public function testBakeEntityHidden() * * @return void */ - public function testBakeEntityCustomHidden() + public function testBakeEntityCustomHidden(): void { $this->generatedFile = APP . 'Model/Entity/User.php'; $this->exec('bake model --no-test --no-fixture --no-table --no-fields --hidden foo,bar users'); @@ -2127,7 +2127,7 @@ public function testBakeEntityCustomHidden() * * @return void */ - public function testBakeTableWithPlugin() + public function testBakeTableWithPlugin(): void { $this->_loadTestPlugin('BakeTest'); $path = Plugin::path('BakeTest'); @@ -2193,7 +2193,7 @@ public function testBakeTableWithEnumConfig(): void * * @return void */ - public function testBakeTableWithCounterCache() + public function testBakeTableWithCounterCache(): void { $this->generatedFile = APP . 'Model/Table/TodoTasksTable.php'; @@ -2211,7 +2211,7 @@ public function testBakeTableWithCounterCache() * * @return void */ - public function testBakeEntityWithPlugin() + public function testBakeEntityWithPlugin(): void { $this->_loadTestPlugin('BakeTest'); $path = Plugin::path('BakeTest'); @@ -2231,7 +2231,7 @@ public function testBakeEntityWithPlugin() * * @return void */ - public function testBakeEntityEnum() + public function testBakeEntityEnum(): void { $this->generatedFile = APP . 'Model/Entity/Article.php'; $this->exec('bake model --no-test --no-fixture --no-table --no-fields Articles'); @@ -2247,7 +2247,7 @@ public function testBakeEntityEnum() * * @return void */ - public function testBakeWithRulesUnique() + public function testBakeWithRulesUnique(): void { $this->generatedFiles = [ APP . 'Model/Table/UsersTable.php', @@ -2389,7 +2389,7 @@ protected function _getName(): string * * @return void */ - public function testMainNoArgs() + public function testMainNoArgs(): void { $this->exec('bake model'); @@ -2402,7 +2402,7 @@ public function testMainNoArgs() * * @return void */ - public function testMainWithNamedModel() + public function testMainWithNamedModel(): void { $this->generatedFiles = [ APP . 'Model/Table/UsersTable.php', @@ -2421,7 +2421,7 @@ public function testMainWithNamedModel() * * @return void */ - public static function nameVariations() + public static function nameVariations(): array { return [ ['TodoItems'], ['todo_items'], @@ -2434,7 +2434,7 @@ public static function nameVariations() * @return void */ #[DataProvider('nameVariations')] - public function testMainWithNamedModelVariations($name) + public function testMainWithNamedModelVariations(string $name): void { $this->generatedFiles = [ APP . 'Model/Table/TodoItemsTable.php', @@ -2453,7 +2453,7 @@ public function testMainWithNamedModelVariations($name) * * @return void */ - public function testBakeTableNullableForeignKey() + public function testBakeTableNullableForeignKey(): void { $this->generatedFiles = [ APP . 'Model/Table/TestBakeArticlesTable.php', diff --git a/tests/TestCase/Command/PluginCommandTest.php b/tests/TestCase/Command/PluginCommandTest.php index 0c6efcf3..a681f35c 100644 --- a/tests/TestCase/Command/PluginCommandTest.php +++ b/tests/TestCase/Command/PluginCommandTest.php @@ -43,7 +43,7 @@ class PluginCommandTest extends TestCase * * @return void */ - public function setUp(): void + protected function setUp(): void { parent::setUp(); $this->_compareBasePath = Plugin::path('Bake') . 'tests' . DS . 'comparisons' . DS . 'Plugin' . DS; @@ -74,7 +74,7 @@ public function setUp(): void * * @return void */ - public function tearDown(): void + protected function tearDown(): void { $fs = new Filesystem(); $fs->deleteDir($this->pluginsPath); @@ -92,14 +92,14 @@ public function tearDown(): void * * @return void */ - public function testMainBakePluginContents() + public function testMainBakePluginContents(): void { $this->exec('bake plugin SimpleExample', ['y', 'n']); $this->assertExitCode(CommandInterface::CODE_SUCCESS); $this->assertPluginContents('SimpleExample'); } - public function testBakingWithNonExistentPluginsDir() + public function testBakingWithNonExistentPluginsDir(): void { $fs = new Filesystem(); $fs->deleteDir($this->pluginsPath); @@ -114,7 +114,7 @@ public function testBakingWithNonExistentPluginsDir() * * @return void */ - public function testMainCustomAppNamespace() + public function testMainCustomAppNamespace(): void { $this->exec('bake plugin Simple', ['y', 'n']); $this->assertExitCode(CommandInterface::CODE_SUCCESS); @@ -129,7 +129,7 @@ public function testMainCustomAppNamespace() * * @return void */ - public function testMainVendorName() + public function testMainVendorName(): void { $this->exec('bake plugin Company/Example --standalone-path ' . $this->pluginsStandalonePath, ['y', 'n']); $this->assertExitCode(CommandInterface::CODE_SUCCESS); @@ -141,7 +141,7 @@ public function testMainVendorName() * * @return void */ - public function testMainVendorNameCasingFix() + public function testMainVendorNameCasingFix(): void { $this->exec('bake plugin company/example --standalone-path ' . $this->pluginsStandalonePath, ['y', 'n']); $this->assertExitCode(CommandInterface::CODE_SUCCESS); @@ -153,7 +153,7 @@ public function testMainVendorNameCasingFix() * * @return void */ - public function testMainWithNoArgs() + public function testMainWithNoArgs(): void { $this->exec('bake plugin'); @@ -167,10 +167,10 @@ public function testMainWithNoArgs() * * @return void */ - public function testMainUpdateComposer() + public function testMainUpdateComposer(): void { $this->skipIf( - DIRECTORY_SEPARATOR == '\\', + DIRECTORY_SEPARATOR === '\\', 'Skipping composer test on windows as `which` does not work well.', ); $composerPath = exec('which composer'); @@ -199,7 +199,7 @@ public function testMainUpdateComposer() * * @return void */ - public function testFindPathNonExistent() + public function testFindPathNonExistent(): void { $io = $this->createStub(ConsoleIo::class); $paths = App::path('plugins'); @@ -221,7 +221,7 @@ public function testFindPathNonExistent() * * @return void */ - public function testFindPathEmpty() + public function testFindPathEmpty(): void { $this->expectException(StopException::class); $io = $this->createStub(ConsoleIo::class); @@ -233,7 +233,7 @@ public function testFindPathEmpty() $command->findPath($paths, $io); } - public function testMainClassOnlyOption() + public function testMainClassOnlyOption(): void { $this->exec('bake plugin ClassOnly --class-only', ['y', 'n']); $this->assertExitCode(CommandInterface::CODE_SUCCESS); @@ -282,7 +282,6 @@ public function assertPluginContents($pluginName, bool $vendor = false): void /** * Get recursive files list for given path. * - * @param string $path * @return string[] */ protected function getFiles(string $path): array @@ -295,7 +294,7 @@ protected function getFiles(string $path): array $iterator = $fs->findRecursive( $path, - function (SplFileInfo $fileInfo) { + function (SplFileInfo $fileInfo): bool { return $fileInfo->isFile(); }, ); diff --git a/tests/TestCase/Command/SimpleBakeCommandTest.php b/tests/TestCase/Command/SimpleBakeCommandTest.php index 1475e8cc..f3b985d8 100644 --- a/tests/TestCase/Command/SimpleBakeCommandTest.php +++ b/tests/TestCase/Command/SimpleBakeCommandTest.php @@ -31,7 +31,7 @@ class SimpleBakeCommandTest extends TestCase * * @return void */ - public function setUp(): void + protected function setUp(): void { parent::setUp(); $this->_compareBasePath = Plugin::path('Bake') . 'tests' . DS . 'comparisons' . DS @@ -44,7 +44,7 @@ public function setUp(): void * * @return void */ - public function testMain() + public function testMain(): void { $this->generatedFiles = [ APP . 'Model/Behavior/ExampleBehavior.php', @@ -62,7 +62,7 @@ public function testMain() * * @return void */ - public function testBake() + public function testBake(): void { $this->generatedFiles = [ APP . 'Model/Behavior/ExampleBehavior.php', @@ -82,7 +82,7 @@ public function testBake() * * @return void */ - public function testBakeTestNoTest() + public function testBakeTestNoTest(): void { $this->generatedFile = APP . 'Model/Behavior/ExampleBehavior.php'; $this->exec('bake behavior --no-test Example'); @@ -92,7 +92,7 @@ public function testBakeTestNoTest() $this->assertFileContains('class ExampleBehavior extends Behavior', $this->generatedFile); } - public function testBakeWithTheme() + public function testBakeWithTheme(): void { $this->_loadTestPlugin('TestBakeTheme'); @@ -108,7 +108,7 @@ public function testBakeWithTheme() * * @return void */ - public function testBakePlugin() + public function testBakePlugin(): void { $this->_loadTestPlugin('TestBake'); $path = Plugin::path('TestBake'); @@ -131,7 +131,7 @@ public function testBakePlugin() * * @return string[][] */ - public static function subclassProvider() + public static function subclassProvider(): array { return [ ['Bake\Command\BehaviorCommand'], @@ -146,11 +146,10 @@ public static function subclassProvider() /** * Test that the various implementations are sane. * - * @dataProvider subclassProvider * @return void */ #[DataProvider('subclassProvider')] - public function testImplementations($class) + public function testImplementations(string $class): void { $task = new $class(); $this->assertIsString($task->name()); diff --git a/tests/TestCase/Command/TemplateAllCommandTest.php b/tests/TestCase/Command/TemplateAllCommandTest.php index d8ce1c46..c420da3f 100644 --- a/tests/TestCase/Command/TemplateAllCommandTest.php +++ b/tests/TestCase/Command/TemplateAllCommandTest.php @@ -49,7 +49,7 @@ class TemplateAllCommandTest extends TestCase * * @return void */ - public function setUp(): void + protected function setUp(): void { parent::setUp(); $this->_compareBasePath = Plugin::path('Bake') . 'tests' . DS . 'comparisons' . DS . 'Template' . DS; @@ -66,7 +66,7 @@ public function setUp(): void * * @return void */ - public function tearDown(): void + protected function tearDown(): void { parent::tearDown(); $connection = ConnectionManager::get('test'); @@ -80,7 +80,7 @@ public function tearDown(): void * * @return void */ - public function testExecuteSimple() + public function testExecuteSimple(): void { $this->generatedFiles = [ ROOT . 'templates/Articles/add.php', @@ -103,7 +103,7 @@ public function testExecuteSimple() * * @return void */ - public function testExecuteOptionForwarding() + public function testExecuteOptionForwarding(): void { $this->generatedFiles = [ ROOT . 'templates/Articles/index.php', diff --git a/tests/TestCase/Command/TemplateCommandTest.php b/tests/TestCase/Command/TemplateCommandTest.php index 7b1ed0fe..6e131825 100644 --- a/tests/TestCase/Command/TemplateCommandTest.php +++ b/tests/TestCase/Command/TemplateCommandTest.php @@ -64,7 +64,7 @@ class TemplateCommandTest extends TestCase * * @return void */ - public function setUp(): void + protected function setUp(): void { parent::setUp(); $this->_compareBasePath = Plugin::path('Bake') . 'tests' . DS . 'comparisons' . DS . 'Template' . DS; @@ -81,7 +81,7 @@ public function setUp(): void * * @return void */ - public function tearDown(): void + protected function tearDown(): void { parent::tearDown(); $this->getTableLocator()->clear(); @@ -92,7 +92,7 @@ public function tearDown(): void * * @return void */ - public function testController() + public function testController(): void { $command = new TemplateCommand(); $args = new Arguments([], [], []); @@ -107,11 +107,10 @@ public function testController() /** * Test the controller() method. * - * @param string $name * @return void */ #[DataProvider('nameVariations')] - public function testControllerVariations($name) + public function testControllerVariations(string $name): void { $command = new TemplateCommand(); $args = new Arguments([], [], []); @@ -124,7 +123,7 @@ public function testControllerVariations($name) * * @return void */ - public function testControllerPlugin() + public function testControllerPlugin(): void { $command = new TemplateCommand(); $command->plugin = 'BakeTest'; @@ -143,7 +142,7 @@ public function testControllerPlugin() * * @return void */ - public function testControllerPrefix() + public function testControllerPrefix(): void { $command = new TemplateCommand(); @@ -169,7 +168,7 @@ public function testControllerPrefix() * * @return void */ - public function testControllerPrefixNested() + public function testControllerPrefixNested(): void { $command = new TemplateCommand(); $args = new Arguments([], ['prefix' => 'Admin/Management'], []); @@ -187,7 +186,7 @@ public function testControllerPrefixNested() * * @return void */ - public function testControllerWithOverride() + public function testControllerWithOverride(): void { $command = new TemplateCommand(); $args = new Arguments([], [], []); @@ -205,7 +204,7 @@ public function testControllerWithOverride() * * @return void */ - public function testModel() + public function testModel(): void { $command = new TemplateCommand(); $command->model('Articles'); @@ -220,7 +219,7 @@ public function testModel() * * @return void */ - public function testModelPlugin() + public function testModelPlugin(): void { $command = new TemplateCommand(); $command->plugin = 'BakeTest'; @@ -236,7 +235,7 @@ public function testModelPlugin() * * @return void */ - public function testGetTemplatePath() + public function testGetTemplatePath(): void { $command = new TemplateCommand(); $command->controllerName = 'Posts'; @@ -263,7 +262,7 @@ public function testGetTemplatePath() * * @return void */ - public function testGetTemplatePathPlugin() + public function testGetTemplatePathPlugin(): void { $pluginPath = APP . 'Plugin/TestTemplate/'; $this->loadPlugins(['TestTemplate' => ['path' => $pluginPath]]); @@ -290,7 +289,7 @@ public function testGetTemplatePathPlugin() * * @return void */ - public function testGetContent() + public function testGetContent(): void { $namespace = Configure::read('App.namespace'); $vars = [ @@ -321,7 +320,7 @@ public function testGetContent() * * @return void */ - public function testGetContentAssociations() + public function testGetContentAssociations(): void { $namespace = Configure::read('App.namespace'); $vars = [ @@ -366,7 +365,7 @@ public function testGetContentAssociations() * * @return void */ - public function testGetContentWithNoPrimaryKey() + public function testGetContentWithNoPrimaryKey(): void { $namespace = Configure::read('App.namespace'); $vars = [ @@ -402,7 +401,7 @@ public function testGetContentWithNoPrimaryKey() * * @return void */ - public function testGetContentWithRoutingPrefix() + public function testGetContentWithRoutingPrefix(): void { $namespace = Configure::read('App.namespace'); @@ -443,7 +442,7 @@ public function testGetContentWithRoutingPrefix() * * @return void */ - public function testBakeView() + public function testBakeView(): void { $this->generatedFile = ROOT . 'templates/Authors/view.php'; $this->exec('bake template authors view'); @@ -460,7 +459,7 @@ public function testBakeView() * * @return void */ - public function testBakeViewEnum() + public function testBakeViewEnum(): void { $table = $this->fetchTable('BakeUsers'); $table->associations()->removeAll(); @@ -481,7 +480,7 @@ public function testBakeViewEnum() * * @return void */ - public function testBakeViewEnumNoLabel() + public function testBakeViewEnumNoLabel(): void { $table = $this->fetchTable('Articles'); $table->getSchema()->setColumnType('published', EnumType::from(ArticleStatus::class)); @@ -501,7 +500,7 @@ public function testBakeViewEnumNoLabel() * * @return void */ - public function testBakeViewHiddenFields() + public function testBakeViewHiddenFields(): void { $this->generatedFile = ROOT . 'templates/HiddenFields/view.php'; $this->exec('bake template HiddenFields view'); @@ -518,7 +517,7 @@ public function testBakeViewHiddenFields() * * @return void */ - public function testBakeEdit() + public function testBakeEdit(): void { $this->generatedFile = ROOT . 'templates/Authors/edit.php'; $this->exec('bake template authors edit'); @@ -535,7 +534,7 @@ public function testBakeEdit() * * @return void */ - public function testBakeEditWithBelongsToManyAssociation() + public function testBakeEditWithBelongsToManyAssociation(): void { $this->generatedFile = ROOT . 'templates/Articles/edit.php'; $this->exec('bake template articles edit'); @@ -552,7 +551,7 @@ public function testBakeEditWithBelongsToManyAssociation() * * @return void */ - public function testBakeIndex() + public function testBakeIndex(): void { $this->generatedFile = ROOT . 'templates/TemplateTaskComments/index.php'; $this->exec('bake template template_task_comments index'); @@ -569,7 +568,7 @@ public function testBakeIndex() * * @return void */ - public function testBakeIndexHiddenFields() + public function testBakeIndexHiddenFields(): void { $this->generatedFile = ROOT . 'templates/HiddenFields/index.php'; $this->exec('bake template HiddenFields index'); @@ -586,7 +585,7 @@ public function testBakeIndexHiddenFields() * * @return void */ - public function testBakeIndexWithIndexLimit() + public function testBakeIndexWithIndexLimit(): void { $this->generatedFile = ROOT . 'templates/TemplateTaskComments/index.php'; $this->exec('bake template template_task_comments --index-columns 3 index'); @@ -603,7 +602,7 @@ public function testBakeIndexWithIndexLimit() * * @return void */ - public function testBakeIndexWithEnumWithLabel() + public function testBakeIndexWithEnumWithLabel(): void { $table = $this->fetchTable('BakeUsers'); $table->getSchema()->setColumnType('status', EnumType::from(BakeUserStatus::class)); @@ -623,7 +622,7 @@ public function testBakeIndexWithEnumWithLabel() * * @return void */ - public function testBakeIndexWithEnumNoLabel() + public function testBakeIndexWithEnumNoLabel(): void { $table = $this->fetchTable('Articles'); $table->getSchema()->setColumnType('published', EnumType::from(ArticleStatus::class)); @@ -643,7 +642,7 @@ public function testBakeIndexWithEnumNoLabel() * * @return void */ - public function testBakeIndexPlugin() + public function testBakeIndexPlugin(): void { $this->_loadTestPlugin('BakeTest'); $path = Plugin::templatePath('BakeTest'); @@ -665,7 +664,7 @@ public function testBakeIndexPlugin() * * @return void */ - public function testBakeTreeNoLftOrRght() + public function testBakeTreeNoLftOrRght(): void { $this->generatedFiles = [ APP . '../templates/CategoryThreads/add.php', @@ -691,7 +690,7 @@ public function testBakeTreeNoLftOrRght() * * @return void */ - public function testBakeSelfAssociationsNoNavLinks() + public function testBakeSelfAssociationsNoNavLinks(): void { $this->generatedFiles = [ APP . '../templates/CategoryThreads/index.php', @@ -710,7 +709,7 @@ public function testBakeSelfAssociationsNoNavLinks() * * @return void */ - public function testBakeSelfAssociationsRelatedAssociations() + public function testBakeSelfAssociationsRelatedAssociations(): void { $this->generatedFile = ROOT . 'templates/CategoryThreads/view.php'; $this->exec('bake template category_threads view'); @@ -727,7 +726,7 @@ public function testBakeSelfAssociationsRelatedAssociations() * * @return void */ - public function testBakeWithNoTemplate() + public function testBakeWithNoTemplate(): void { $this->expectException(MissingTemplateException::class); $this->expectExceptionMessage('No bake template found for "Bake.Template/delete"'); @@ -739,7 +738,7 @@ public function testBakeWithNoTemplate() * * @return void */ - public function testMainNoArgs() + public function testMainNoArgs(): void { $this->exec('bake template'); @@ -754,7 +753,7 @@ public function testMainNoArgs() * * @return void */ - public function testMainWithActionParam() + public function testMainWithActionParam(): void { $this->generatedFile = ROOT . 'templates/TemplateTaskComments/view.php'; $this->exec('bake template TemplateTaskComments view'); @@ -777,7 +776,7 @@ public function testMainWithActionParam() * * @return void */ - public function testMainWithExistingController() + public function testMainWithExistingController(): void { $this->generatedFiles = [ ROOT . 'templates/TemplateTaskComments/index.php', @@ -802,7 +801,7 @@ public function testMainWithExistingController() * * @return void */ - public function testMainWithPluginName() + public function testMainWithPluginName(): void { $this->_loadTestPlugin('TestBake'); $path = Plugin::templatePath('TestBake'); @@ -823,7 +822,7 @@ public function testMainWithPluginName() * * @return void */ - public static function nameVariations() + public static function nameVariations(): array { return [['TemplateTaskComments'], ['template_task_comments']]; } @@ -833,7 +832,7 @@ public static function nameVariations() * * @return void */ - public function testMainWithControllerFlag() + public function testMainWithControllerFlag(): void { $this->generatedFiles = [ ROOT . 'templates/Blog/index.php', @@ -854,7 +853,7 @@ public function testMainWithControllerFlag() * * @return void */ - public function testMainWithControllerAndAdminFlag() + public function testMainWithControllerAndAdminFlag(): void { $this->generatedFiles = [ ROOT . 'templates/Admin/Posts/index.php', @@ -871,7 +870,7 @@ public function testMainWithControllerAndAdminFlag() * * @return void */ - public function testMainWithAlternateTemplates() + public function testMainWithAlternateTemplates(): void { $this->generatedFile = ROOT . 'templates/TemplateTaskComments/list.php'; $this->exec('bake template TemplateTaskComments index list'); @@ -886,7 +885,7 @@ public function testMainWithAlternateTemplates() * * @return void */ - public function testMainWithMissingTable() + public function testMainWithMissingTable(): void { $this->exec('bake template MissingTableClass'); @@ -901,7 +900,7 @@ public function testMainWithMissingTable() * * @return void */ - public function testBakeIndexWithSingularPluralCollision() + public function testBakeIndexWithSingularPluralCollision(): void { $this->generatedFile = ROOT . 'templates/News/index.php'; $this->exec('bake template News index'); diff --git a/tests/TestCase/Command/TestCommandTest.php b/tests/TestCase/Command/TestCommandTest.php index b2552ce6..9cfa3135 100644 --- a/tests/TestCase/Command/TestCommandTest.php +++ b/tests/TestCase/Command/TestCommandTest.php @@ -49,14 +49,14 @@ class TestCommandTest extends TestCase * * @return void */ - public function setUp(): void + protected function setUp(): void { parent::setUp(); $this->setAppNamespace('Bake\Test\App'); $this->_compareBasePath = Plugin::path('Bake') . 'tests' . DS . 'comparisons' . DS . 'Test' . DS; } - public function tearDown(): void + protected function tearDown(): void { parent::tearDown(); $this->getTableLocator()->clear(); @@ -68,7 +68,7 @@ public function tearDown(): void * * @return void */ - public function testExecuteNoArgsPrintsTypeOptions() + public function testExecuteNoArgsPrintsTypeOptions(): void { $this->exec('bake test'); @@ -85,7 +85,7 @@ public function testExecuteNoArgsPrintsTypeOptions() * * @return void */ - public function testExecuteOneArgPrintsClassOptions() + public function testExecuteOneArgPrintsClassOptions(): void { $this->exec('bake test entity'); @@ -98,7 +98,7 @@ public function testExecuteOneArgPrintsClassOptions() * * @return void */ - public function testExecuteWithTwoArgs() + public function testExecuteWithTwoArgs(): void { $this->generatedFiles = [ ROOT . 'tests/TestCase/Model/Table/TestTaskTagTableTest.php', @@ -118,7 +118,7 @@ public function testExecuteWithTwoArgs() * * @return void */ - public function testExecuteWithPluginName() + public function testExecuteWithPluginName(): void { $this->_loadTestPlugin('TestBake'); @@ -144,7 +144,7 @@ public function testExecuteWithPluginName() * * @return void */ - public function testExecuteWithAll() + public function testExecuteWithAll(): void { $this->generatedFiles = [ ROOT . 'tests/TestCase/Model/Table/ArticlesTableTest.php', @@ -166,7 +166,7 @@ public function testExecuteWithAll() * * @return void */ - public function testOutputClassOptionsForTable() + public function testOutputClassOptionsForTable(): void { $this->exec('bake test table'); @@ -187,7 +187,7 @@ public function testOutputClassOptionsForTable() * * @return void */ - public function testOutputClassOptionsForTablePlugin() + public function testOutputClassOptionsForTablePlugin(): void { $this->loadPlugins(['BakeTest' => ['path' => ROOT . 'Plugin' . DS . 'BakeTest' . DS]]); $this->exec('bake test table --plugin BakeTest'); @@ -206,7 +206,7 @@ public function testOutputClassOptionsForTablePlugin() * * @return void */ - public function testMethodIntrospection() + public function testMethodIntrospection(): void { $command = new TestCommand(); $result = $command->getTestableMethods('Bake\Test\App\Model\Table\ArticlesTable'); @@ -219,7 +219,7 @@ public function testMethodIntrospection() * * @return void */ - public function testFixtureArrayGenerationFromModel() + public function testFixtureArrayGenerationFromModel(): void { $command = new TestCommand(); $subject = new ArticlesTable(); @@ -238,7 +238,7 @@ public function testFixtureArrayGenerationFromModel() * * @return void */ - public function testFixtureArrayGenerationIgnoreSelfAssociation() + public function testFixtureArrayGenerationIgnoreSelfAssociation(): void { $this->getTableLocator()->clear(); $subject = new CategoryThreadsTable(); @@ -255,7 +255,7 @@ public function testFixtureArrayGenerationIgnoreSelfAssociation() * * @return void */ - public function testFixtureGenerationFromController() + public function testFixtureGenerationFromController(): void { $subject = new PostsController(new Request()); $command = new TestCommand(); @@ -271,7 +271,7 @@ public function testFixtureGenerationFromController() * * @return array */ - public static function realClassProvider() + public static function realClassProvider(): array { return [ ['Entity', 'Article', 'App\Model\Entity\Article'], @@ -295,7 +295,7 @@ public static function realClassProvider() * @return void */ #[DataProvider('realClassProvider')] - public function testGetRealClassname($type, $name, $expected) + public function testGetRealClassname(string $type, string $name, string $expected): void { $this->setAppNamespace('App'); @@ -309,7 +309,7 @@ public function testGetRealClassname($type, $name, $expected) * * @return void */ - public function testGetRealClassnamePlugin() + public function testGetRealClassnamePlugin(): void { $this->_loadTestPlugin('TestBake'); $command = new TestCommand(); @@ -325,7 +325,7 @@ public function testGetRealClassnamePlugin() * * @return void */ - public function testGetRealClassnamePrefix() + public function testGetRealClassnamePrefix(): void { $command = new TestCommand(); $result = $command->getRealClassname('Controller', 'Posts', 'Api/Public'); @@ -339,7 +339,7 @@ public function testGetRealClassnamePrefix() * * @return void */ - public function testBakeFixturesParam() + public function testBakeFixturesParam(): void { $this->generatedFiles = [ ROOT . 'tests/TestCase/Model/Table/AuthorsTableTest.php', @@ -356,7 +356,7 @@ public function testBakeFixturesParam() * * @return void */ - public function testBakeNoFixtureParam() + public function testBakeNoFixtureParam(): void { $this->generatedFiles = [ ROOT . 'tests/TestCase/Model/Table/AuthorsTableTest.php', @@ -373,7 +373,7 @@ public function testBakeNoFixtureParam() * * @return void */ - public function testBakeCellTest() + public function testBakeCellTest(): void { $this->generatedFiles = [ ROOT . 'tests/TestCase/View/Cell/ArticlesCellTest.php', @@ -390,7 +390,7 @@ public function testBakeCellTest() * * @return void */ - public function testBakeCommandTest() + public function testBakeCommandTest(): void { $this->generatedFiles = [ ROOT . 'tests/TestCase/Command/OtherExampleCommandTest.php', @@ -407,7 +407,7 @@ public function testBakeCommandTest() * * @return void */ - public function testBakeModelTest() + public function testBakeModelTest(): void { $this->generatedFiles = [ ROOT . 'tests/TestCase/Model/Table/ArticlesTableTest.php', @@ -424,7 +424,7 @@ public function testBakeModelTest() * * @return void */ - public function testBakeControllerTest() + public function testBakeControllerTest(): void { $this->generatedFiles = [ ROOT . 'tests/TestCase/Controller/PostsControllerTest.php', @@ -441,7 +441,7 @@ public function testBakeControllerTest() * * @return void */ - public function testBakeControllerWithoutModelTest() + public function testBakeControllerWithoutModelTest(): void { $this->generatedFiles = [ ROOT . 'tests/TestCase/Controller/NoModelControllerTest.php', @@ -458,7 +458,7 @@ public function testBakeControllerWithoutModelTest() * * @return void */ - public function testBakePrefixControllerTest() + public function testBakePrefixControllerTest(): void { $this->generatedFiles = [ ROOT . 'tests/TestCase/Controller/Admin/PostsControllerTest.php', @@ -475,7 +475,7 @@ public function testBakePrefixControllerTest() * * @return void */ - public function testBakePrefixControllerTestWithCliOption() + public function testBakePrefixControllerTestWithCliOption(): void { $this->generatedFiles = [ ROOT . 'tests/TestCase/Controller/Admin/PostsControllerTest.php', @@ -492,7 +492,7 @@ public function testBakePrefixControllerTestWithCliOption() * * @return void */ - public function testBakeComponentTest() + public function testBakeComponentTest(): void { $this->generatedFiles = [ ROOT . 'tests/TestCase/Controller/Component/AppleComponentTest.php', @@ -509,7 +509,7 @@ public function testBakeComponentTest() * * @return void */ - public function testBakeBehaviorTest() + public function testBakeBehaviorTest(): void { $this->generatedFiles = [ ROOT . 'tests/TestCase/Model/Behavior/ExampleBehaviorTest.php', @@ -526,7 +526,7 @@ public function testBakeBehaviorTest() * * @return void */ - public function testBakeHelperTest() + public function testBakeHelperTest(): void { $this->generatedFiles = [ ROOT . 'tests/TestCase/View/Helper/ExampleHelperTest.php', @@ -543,7 +543,7 @@ public function testBakeHelperTest() * * @return void */ - public function testBakeUnknownClass() + public function testBakeUnknownClass(): void { $this->exec('bake test Foo Example'); @@ -555,7 +555,7 @@ public function testBakeUnknownClass() * * @return void */ - public function testGenerateConstructor() + public function testGenerateConstructor(): void { $command = new TestCommand(); $result = $command->generateConstructor('Controller', 'PostsController'); @@ -600,7 +600,7 @@ public function testGenerateConstructor() * * @return void */ - public function testGenerateUses() + public function testGenerateUses(): void { $command = new TestCommand(); $result = $command->generateUses('Table', 'App\Model\Table\PostsTable'); @@ -628,7 +628,7 @@ public function testGenerateUses() * * @return void */ - public function testMockClassGeneration() + public function testMockClassGeneration(): void { $command = new TestCommand(); $result = $command->hasMockClass('Controller'); @@ -640,7 +640,7 @@ public function testMockClassGeneration() * * @return array */ - public static function caseFileNameProvider() + public static function caseFileNameProvider(): array { return [ ['Table', 'App\Model\Table\PostsTable', 'TestCase/Model/Table/PostsTableTest.php'], @@ -663,7 +663,7 @@ public static function caseFileNameProvider() * @return void */ #[DataProvider('caseFileNameProvider')] - public function testTestCaseFileName($type, $class, $expected) + public function testTestCaseFileName(string $type, string $class, string $expected): void { $this->setAppNamespace('App'); $command = new TestCommand(); @@ -677,7 +677,7 @@ public function testTestCaseFileName($type, $class, $expected) * * @return void */ - public function testTestCaseFileNamePlugin() + public function testTestCaseFileNamePlugin(): void { $this->loadPlugins([ 'TestTest' => [ @@ -698,7 +698,7 @@ public function testTestCaseFileNamePlugin() * * @return array */ - public static function mapTypeProvider() + public static function mapTypeProvider(): array { return [ ['Controller', 'Controller'], @@ -717,7 +717,7 @@ public static function mapTypeProvider() * @return void */ #[DataProvider('mapTypeProvider')] - public function testMapType($original, $expected) + public function testMapType(string $original, string $expected): void { $command = new TestCommand(); $this->assertEquals($expected, $command->mapType($original)); @@ -728,7 +728,7 @@ public function testMapType($original, $expected) * * @return void */ - public function testGenerateUsesDocBlockController() + public function testGenerateUsesDocBlockController(): void { $testsPath = ROOT . 'tests' . DS; @@ -746,7 +746,7 @@ public function testGenerateUsesDocBlockController() * * @return void */ - public function testGenerateUsesDocBlockTable() + public function testGenerateUsesDocBlockTable(): void { $testsPath = ROOT . 'tests' . DS; @@ -768,7 +768,7 @@ public function testGenerateUsesDocBlockTable() * * @return void */ - public function testBakeGenericClassWithoutConstructor() + public function testBakeGenericClassWithoutConstructor(): void { $testsPath = ROOT . 'tests' . DS; $this->generatedFiles = [ @@ -810,7 +810,7 @@ public function testBakeGenericClassWithoutConstructor() * * @return void */ - public function testBakeGenericClassWithRequiredConstructor() + public function testBakeGenericClassWithRequiredConstructor(): void { $testsPath = ROOT . 'tests' . DS; $this->generatedFiles = [ @@ -852,7 +852,7 @@ public function testBakeGenericClassWithRequiredConstructor() * * @return void */ - public function testBakeGenericClassNamespace() + public function testBakeGenericClassNamespace(): void { $testsPath = ROOT . 'tests' . DS; $this->generatedFiles = [ @@ -881,7 +881,7 @@ public function testBakeGenericClassNamespace() * * @return void */ - public function testBakeGenericClassWithBaseNamespace() + public function testBakeGenericClassWithBaseNamespace(): void { $testsPath = ROOT . 'tests' . DS; $this->generatedFiles = [ @@ -916,7 +916,7 @@ public function testBakeGenericClassWithBaseNamespace() * * @return void */ - public function testBakeGenericClassValidatesBackslashes() + public function testBakeGenericClassValidatesBackslashes(): void { // Simulate what happens when user doesn't quote: App\Error\ErrorLogger // Bash strips backslashes resulting in: AppErrorErrorLogger diff --git a/tests/TestCase/PluginTest.php b/tests/TestCase/PluginTest.php index 2a4fa73c..8f970bda 100644 --- a/tests/TestCase/PluginTest.php +++ b/tests/TestCase/PluginTest.php @@ -27,13 +27,13 @@ */ class PluginTest extends TestCase { - public function tearDown(): void + protected function tearDown(): void { parent::tearDown(); $this->removePlugins(['BakeTest', 'WithBakeSubFolder']); } - public function testRoutes() + public function testRoutes(): void { $collection = new RouteCollection(); $routes = new RouteBuilder($collection, '/'); @@ -43,7 +43,7 @@ public function testRoutes() $this->assertCount(0, $collection->routes()); } - public function testConsoleDiscoverBakeCommands() + public function testConsoleDiscoverBakeCommands(): void { Plugin::getCollection()->add(new BakePlugin()); $commands = new CommandCollection(); @@ -62,7 +62,7 @@ public function testConsoleDiscoverBakeCommands() $this->assertFalse($commands->has('bake bake_command')); } - public function testConsoleDiscoverPluginCommands() + public function testConsoleDiscoverPluginCommands(): void { $this->_loadTestPlugin('BakeTest'); @@ -75,7 +75,7 @@ public function testConsoleDiscoverPluginCommands() $this->assertFalse($commands->has('bake BakeTest.zergling')); } - public function testConsoleDiscoverPluginCommandsInSubFolder() + public function testConsoleDiscoverPluginCommandsInSubFolder(): void { $this->_loadTestPlugin('WithBakeSubFolder'); @@ -90,7 +90,7 @@ public function testConsoleDiscoverPluginCommandsInSubFolder() ); } - public function testConsoleDiscoverAppCommands() + public function testConsoleDiscoverAppCommands(): void { $this->setAppNamespace('Bake\Test\App'); diff --git a/tests/TestCase/TestCase.php b/tests/TestCase/TestCase.php index 32b8b15d..37650961 100644 --- a/tests/TestCase/TestCase.php +++ b/tests/TestCase/TestCase.php @@ -36,7 +36,7 @@ abstract class TestCase extends BaseTestCase */ protected $generatedFiles = []; - public function setUp(): void + protected function setUp(): void { parent::setUp(); Router::reload(); @@ -44,7 +44,7 @@ public function setUp(): void $this->loadPlugins(['Cake/TwigView']); } - public function tearDown(): void + protected function tearDown(): void { parent::tearDown(); @@ -72,7 +72,7 @@ public function tearDown(): void */ protected function _loadTestPlugin(string $name, bool $loadBake = false): void { - $root = dirname(dirname(__FILE__)) . DS; + $root = dirname(__FILE__, 2) . DS; $path = $root . 'test_app' . DS . 'Plugin' . DS . $name . DS; $plugins = [ diff --git a/tests/TestCase/Utility/Model/AssociationFilterTest.php b/tests/TestCase/Utility/Model/AssociationFilterTest.php index d87c97f5..ae6c7d7a 100644 --- a/tests/TestCase/Utility/Model/AssociationFilterTest.php +++ b/tests/TestCase/Utility/Model/AssociationFilterTest.php @@ -53,7 +53,7 @@ class AssociationFilterTest extends TestCase * * @return void */ - public function setUp(): void + protected function setUp(): void { parent::setUp(); $this->associationFilter = new AssociationFilter(); @@ -64,7 +64,7 @@ public function setUp(): void * * @return void */ - public function tearDown(): void + protected function tearDown(): void { $this->getTableLocator()->clear(); unset($this->associationFilter); @@ -76,7 +76,7 @@ public function tearDown(): void * * @return void */ - public function testFilterHasManyAssociationsAliases() + public function testFilterHasManyAssociationsAliases(): void { $table = $this->getTableLocator()->get('Articles', [ 'className' => '\Bake\Test\App\Model\Table\ArticlesTable', @@ -95,7 +95,7 @@ public function testFilterHasManyAssociationsAliases() * * @return void */ - public function testFilterHasManyAssociationsAliasesExtra() + public function testFilterHasManyAssociationsAliasesExtra(): void { $table = $this->getTableLocator()->get('Articles', [ 'className' => '\Bake\Test\App\Model\Table\ArticlesTable', @@ -122,7 +122,7 @@ public function testFilterHasManyAssociationsAliasesExtra() * * @return void */ - public function testFilterAssociations() + public function testFilterAssociations(): void { $table = $this->getTableLocator()->get('Articles', [ 'className' => '\Bake\Test\App\Model\Table\ArticlesTable', @@ -144,7 +144,7 @@ public function testFilterAssociations() * * @return void */ - public function testFilterAssociationsSelf() + public function testFilterAssociationsSelf(): void { $table = $this->getTableLocator()->get('CategoryThreads', [ 'className' => '\Bake\Test\App\Model\Table\CategoryThreadsTable', @@ -161,7 +161,7 @@ public function testFilterAssociationsSelf() * * @return void */ - public function testFilterAssociationsMissingTable() + public function testFilterAssociationsMissingTable(): void { $table = $this->getTableLocator()->get('Articles', [ 'className' => '\Bake\Test\App\Model\Table\ArticlesTable', diff --git a/tests/TestCase/Utility/TableScannerTest.php b/tests/TestCase/Utility/TableScannerTest.php index ab14bec0..cbc51461 100644 --- a/tests/TestCase/Utility/TableScannerTest.php +++ b/tests/TestCase/Utility/TableScannerTest.php @@ -45,7 +45,7 @@ class TableScannerTest extends TestCase * * @return void */ - public function setUp(): void + protected function setUp(): void { parent::setUp(); @@ -57,7 +57,7 @@ public function setUp(): void * * @return void */ - public function tearDown(): void + protected function tearDown(): void { parent::tearDown(); unset($this->tableScanner); @@ -66,7 +66,7 @@ public function tearDown(): void /** * @return void */ - public function testListAll() + public function testListAll(): void { $this->tableScanner = new TableScanner($this->connection); @@ -87,7 +87,7 @@ public function testListAll() /** * @return void */ - public function testListUnskipped() + public function testListUnskipped(): void { $this->tableScanner = new TableScanner($this->connection, ['todo_items']); @@ -108,7 +108,7 @@ public function testListUnskipped() /** * @return void */ - public function testListUnskippedRegex() + public function testListUnskippedRegex(): void { $this->tableScanner = new TableScanner($this->connection, ['/tasks$/']); diff --git a/tests/TestCase/Utility/TemplateRendererTest.php b/tests/TestCase/Utility/TemplateRendererTest.php index 05807740..a44e092c 100644 --- a/tests/TestCase/Utility/TemplateRendererTest.php +++ b/tests/TestCase/Utility/TemplateRendererTest.php @@ -35,7 +35,7 @@ class TemplateRendererTest extends TestCase * * @return void */ - public function setUp(): void + protected function setUp(): void { parent::setUp(); $this->_compareBasePath = Plugin::path('Bake') . 'tests' . DS . 'comparisons' . DS . 'TemplateRenderer' . DS; @@ -47,7 +47,7 @@ public function setUp(): void * * @return void */ - public function tearDown(): void + protected function tearDown(): void { parent::tearDown(); unset($this->renderer); @@ -59,7 +59,7 @@ public function tearDown(): void * * @return void */ - public function testGenerate() + public function testGenerate(): void { $result = $this->renderer->generate('example', ['test' => 'foo']); $this->assertSameAsFile(__FUNCTION__ . '.php', $result); @@ -70,7 +70,7 @@ public function testGenerate() * * @return void */ - public function testGenerateWithTemplateOverride() + public function testGenerateWithTemplateOverride(): void { $this->_loadTestPlugin('TestBakeTheme', true); $renderer = new TemplateRenderer('TestBakeTheme'); @@ -87,7 +87,7 @@ public function testGenerateWithTemplateOverride() * * @return void */ - public function testGenerateWithTemplateFallbacks() + public function testGenerateWithTemplateFallbacks(): void { $this->_loadTestPlugin('TestBakeTheme', true); $renderer = new TemplateRenderer('TestBakeTheme'); diff --git a/tests/TestCase/View/BakeViewTest.php b/tests/TestCase/View/BakeViewTest.php index eb3422fb..ece9d31d 100644 --- a/tests/TestCase/View/BakeViewTest.php +++ b/tests/TestCase/View/BakeViewTest.php @@ -41,7 +41,7 @@ class BakeViewTest extends TestCase * * @return void */ - public function setUp(): void + protected function setUp(): void { parent::setUp(); $this->_compareBasePath = Plugin::path('Bake') . 'tests' . DS . 'comparisons' . DS . 'BakeView' . DS; @@ -56,7 +56,7 @@ public function setUp(): void * * @return void */ - public function tearDown(): void + protected function tearDown(): void { parent::tearDown(); unset($this->View); @@ -67,7 +67,7 @@ public function tearDown(): void * * @return void */ - public function testRenderTemplate() + public function testRenderTemplate(): void { $this->View->set(['aVariable' => 123]); $result = $this->View->render('simple'); @@ -81,7 +81,7 @@ public function testRenderTemplate() * * @return void */ - public function testRenderIgnorePhpTags() + public function testRenderIgnorePhpTags(): void { $this->View->set(['aVariable' => 123]); $result = $this->View->render('simple_php'); @@ -95,7 +95,7 @@ public function testRenderIgnorePhpTags() * * @return void */ - public function testRenderIgnorePhpShortTags() + public function testRenderIgnorePhpShortTags(): void { $this->View->set(['aVariable' => 123]); $result = $this->View->render('simple_php_short_tags'); @@ -109,7 +109,7 @@ public function testRenderIgnorePhpShortTags() * * @return void */ - public function testRenderNewlines() + public function testRenderNewlines(): void { $result = $this->View->render('newlines'); $expected = "There should be a newline about here: \n"; @@ -129,7 +129,7 @@ public function testRenderNewlines() * * @return void */ - public function testSwallowLeadingWhitespace() + public function testSwallowLeadingWhitespace(): void { $result = $this->View->render('leading_whitespace'); $this->assertSameAsFile(__FUNCTION__ . '.php', $result); @@ -140,7 +140,7 @@ public function testSwallowLeadingWhitespace() * * @return void */ - public function testNoLineBreaks() + public function testNoLineBreaks(): void { $result = $this->View->render('no_line_breaks'); $this->assertSameAsFile(__FUNCTION__ . '.php', $result); @@ -152,7 +152,7 @@ public function testNoLineBreaks() * * @return void */ - public function testSeparatorRenderEvents() + public function testSeparatorRenderEvents(): void { $this->View->set('test', 'success'); $result = $this->View->render('Custom' . DS . 'file'); @@ -162,10 +162,10 @@ public function testSeparatorRenderEvents() ); $this->View->set('test', 'success'); - $this->View->getEventManager()->on('Bake.beforeRender.Custom.file', function (Event $event) { + $this->View->getEventManager()->on('Bake.beforeRender.Custom.file', function (Event $event): void { $event->getSubject()->set('test', 'separator constant beforeRender'); }); - $this->View->getEventManager()->on('Bake.afterRender.Custom.file', function (Event $event) { + $this->View->getEventManager()->on('Bake.afterRender.Custom.file', function (Event $event): void { $event->getSubject()->set('test', 'separator constant afterRender'); }); $result = $this->View->render('Custom' . DS . 'file'); @@ -176,10 +176,10 @@ public function testSeparatorRenderEvents() $this->assertSame($this->View->get('test'), 'separator constant afterRender'); $this->View->set('test', 'success'); - $this->View->getEventManager()->on('Bake.beforeRender.Custom.file', function (Event $event) { + $this->View->getEventManager()->on('Bake.beforeRender.Custom.file', function (Event $event): void { $event->getSubject()->set('test', 'fixed separator beforeRender'); }); - $this->View->getEventManager()->on('Bake.afterRender.Custom.file', function (Event $event) { + $this->View->getEventManager()->on('Bake.afterRender.Custom.file', function (Event $event): void { $event->getSubject()->set('test', 'fixed separator afterRender'); }); $result = $this->View->render('Custom/file'); @@ -195,7 +195,7 @@ public function testSeparatorRenderEvents() * * @return void */ - public function testPluginRenderEvents() + public function testPluginRenderEvents(): void { $this->View->set('test', 'success'); $result = $this->View->render('Bake.Custom' . DS . 'file'); @@ -205,10 +205,10 @@ public function testPluginRenderEvents() ); $this->View->set('test', 'success'); - $this->View->getEventManager()->on('Bake.beforeRender.Custom.file', function (Event $event) { + $this->View->getEventManager()->on('Bake.beforeRender.Custom.file', function (Event $event): void { $event->getSubject()->set('test', 'plugin template beforeRender'); }); - $this->View->getEventManager()->on('Bake.afterRender.Custom.file', function (Event $event) { + $this->View->getEventManager()->on('Bake.afterRender.Custom.file', function (Event $event): void { $event->getSubject()->set('test', 'plugin template afterRender'); }); $result = $this->View->render('Bake.Custom' . DS . 'file'); @@ -224,7 +224,7 @@ public function testPluginRenderEvents() * * @return void */ - public function testCustomRenderEvents() + public function testCustomRenderEvents(): void { $this->View->set('test', 'success'); $result = $this->View->render('Custom' . DS . 'file'); @@ -234,10 +234,10 @@ public function testCustomRenderEvents() ); $this->View->set('test', 'success'); - $this->View->getEventManager()->on('Bake.beforeRender.Custom.file', function (Event $event) { + $this->View->getEventManager()->on('Bake.beforeRender.Custom.file', function (Event $event): void { $event->getSubject()->set('test', 'custom template beforeRender'); }); - $this->View->getEventManager()->on('Bake.afterRender.Custom.file', function (Event $event) { + $this->View->getEventManager()->on('Bake.afterRender.Custom.file', function (Event $event): void { $event->getSubject()->set('test', 'custom template afterRender'); }); $result = $this->View->render('Custom' . DS . 'file'); @@ -253,7 +253,7 @@ public function testCustomRenderEvents() * * @return void */ - public function testApplicationOverride() + public function testApplicationOverride(): void { $result = $this->View->render('Bake.override'); $this->assertSame("Application override.\n", $result); diff --git a/tests/TestCase/View/Helper/BakeHelperTest.php b/tests/TestCase/View/Helper/BakeHelperTest.php index 9fb54c5b..4e1bbfd9 100644 --- a/tests/TestCase/View/Helper/BakeHelperTest.php +++ b/tests/TestCase/View/Helper/BakeHelperTest.php @@ -60,7 +60,7 @@ class BakeHelperTest extends TestCase * * @return void */ - public function setUp(): void + protected function setUp(): void { parent::setUp(); @@ -75,7 +75,7 @@ public function setUp(): void * * @return void */ - public function tearDown(): void + protected function tearDown(): void { parent::tearDown(); unset($this->BakeHelper); @@ -86,7 +86,7 @@ public function tearDown(): void * * @return void */ - public function testAliasExtractorFilteredHasMany() + public function testAliasExtractorFilteredHasMany(): void { $table = $this->getTableLocator()->get('Articles', [ 'className' => '\Bake\Test\App\Model\Table\ArticlesTable', @@ -107,7 +107,7 @@ public function testAliasExtractorFilteredHasMany() * * @return void */ - public function testAliasExtractorBelongsTo() + public function testAliasExtractorBelongsTo(): void { $table = $this->getTableLocator()->get('Articles', [ 'className' => '\Bake\Test\App\Model\Table\ArticlesTable', @@ -122,7 +122,7 @@ public function testAliasExtractorBelongsTo() * * @return void */ - public function testAliasExtractorBelongsToMany() + public function testAliasExtractorBelongsToMany(): void { $table = $this->getTableLocator()->get('Articles', [ 'className' => '\Bake\Test\App\Model\Table\ArticlesTable', @@ -137,7 +137,7 @@ public function testAliasExtractorBelongsToMany() * * @return void */ - public function testEscapeArguments() + public function testEscapeArguments(): void { $arguments = [ 100, diff --git a/tests/TestCase/View/Helper/DocBlockHelperTest.php b/tests/TestCase/View/Helper/DocBlockHelperTest.php index a2c692ab..1fc832bf 100644 --- a/tests/TestCase/View/Helper/DocBlockHelperTest.php +++ b/tests/TestCase/View/Helper/DocBlockHelperTest.php @@ -49,7 +49,7 @@ class DocBlockHelperTest extends TestCase * * @return void */ - public function setUp(): void + protected function setUp(): void { parent::setUp(); @@ -64,7 +64,7 @@ public function setUp(): void * * @return void */ - public function tearDown(): void + protected function tearDown(): void { parent::tearDown(); unset($this->DocBlockHelper); @@ -75,7 +75,7 @@ public function tearDown(): void * * @return void */ - public function testClassDescription() + public function testClassDescription(): void { $className = 'Comments'; $classType = 'Model'; @@ -94,7 +94,7 @@ public function testClassDescription() * * @return void */ - public function testAssociatedEntityTypeToHintType() + public function testAssociatedEntityTypeToHintType(): void { // Test with MANY_TO_MANY $type = 'Foo'; @@ -130,7 +130,7 @@ public function testAssociatedEntityTypeToHintType() * * @return void */ - public function testBuildEntityPropertyHintTypeMap() + public function testBuildEntityPropertyHintTypeMap(): void { $map = [ 'string' => [ @@ -197,7 +197,7 @@ public function testBuildEntityPropertyHintTypeMap() * * @return void */ - public function testBuildEntityAssociationHintTypeMap() + public function testBuildEntityAssociationHintTypeMap(): void { $this->markTestIncomplete('Not implemented yet'); } @@ -207,7 +207,7 @@ public function testBuildEntityAssociationHintTypeMap() * * @return void */ - public function testColumnTypeToHintType() + public function testColumnTypeToHintType(): void { $this->markTestIncomplete('Not implemented yet'); } @@ -217,7 +217,7 @@ public function testColumnTypeToHintType() * * @return void */ - public function testPropertyHints() + public function testPropertyHints(): void { $this->markTestIncomplete('Not implemented yet'); } @@ -227,7 +227,7 @@ public function testPropertyHints() * * @return void */ - public function testBuildTableAnnotations() + public function testBuildTableAnnotations(): void { $this->markTestIncomplete('Not implemented yet'); } diff --git a/tests/bootstrap.php b/tests/bootstrap.php index a031b40e..6e3329f5 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -25,10 +25,10 @@ use Cake\Error\Debug\TextFormatter; use Cake\TestSuite\Fixture\SchemaLoader; -$findRoot = function ($root) { +$findRoot = function ($root): string { do { $lastRoot = $root; - $root = dirname($root); + $root = dirname((string) $root); if (is_dir($root . '/vendor/cakephp/cakephp')) { return $root; } @@ -39,7 +39,7 @@ unset($findRoot); chdir($root); -require_once 'vendor/autoload.php'; +require_once __DIR__ . '/../vendor/autoload.php'; define('ROOT', $root . DS . 'tests' . DS . 'test_app' . DS); define('APP', ROOT . 'App' . DS);