Skip to content

Commit

Permalink
CakePHP 5.x updates and clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
Daren Sipes committed Apr 19, 2024
1 parent 0ad68b0 commit eef2d11
Show file tree
Hide file tree
Showing 36 changed files with 377 additions and 985 deletions.
38 changes: 38 additions & 0 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="3.14.2@3538fe1955d47f6ee926c0769d71af6db08aa488">
<file src="src/Command/CopyLayoutsCommand.php">
<InternalClass occurrences="1">
<code>new Filesystem()</code>
</InternalClass>
<InternalMethod occurrences="1">
<code>copyDir</code>
</InternalMethod>
</file>
<file src="src/Command/InstallCommand.php">
<ForbiddenCode occurrences="1">
<code>`$command`</code>
</ForbiddenCode>
<InternalClass occurrences="4">
<code>new Filesystem()</code>
<code>new Filesystem()</code>
<code>new Filesystem()</code>
<code>new Filesystem()</code>
</InternalClass>
<InternalMethod occurrences="5">
<code>deleteDir</code>
<code>findRecursive</code>
<code>mkdir</code>
<code>mkdir</code>
<code>findRecursive</code>
</InternalMethod>
<NullReference occurrences="2">
<code>$output</code>
<code>$return</code>
</NullReference>
</file>
<file src="vendor/cakephp/cakephp/src/View/View.php">
<UnsafeInstantiation occurrences="1">
<code>new $this-&gt;_viewBlockClass()</code>
</UnsafeInstantiation>
</file>
</files>
56 changes: 28 additions & 28 deletions src/Plugin.php → src/ButterCreamPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
use ReflectionException;

/**
* Plugin for Client
* Plugin for ButterCream
*/
class Plugin extends BasePlugin
class ButterCreamPlugin extends BasePlugin
{
/**
* Plugin name.
Expand Down Expand Up @@ -107,46 +107,46 @@ protected function discoverCommands(CommandCollection $commands): CommandCollect
*
* @param string $namespace The namespace classes are expected to be in.
* @param string $path The path to look in.
* @return array
* @return array<string>
* @psalm-return array<string, class-string<\Bake\Command\BakeCommand>>
*/
protected function findInPath(string $namespace, string $path): array
{
$hasSubfolder = false;
$path .= 'Command/';
if (!file_exists($path)) {
$namespace .= '\Command\\';

if (file_exists($path . 'Bake/')) {
$hasSubfolder = true;
$path .= 'Bake/';
$namespace .= 'Bake\\';
} elseif (!file_exists($path)) {
return [];
}

$iterator = new DirectoryIterator($path);
$candidates = [];
foreach ($iterator as $item) {
if ($item->isDot() || $item->isDir()) {
continue;
}
$class = $namespace . '\Command\\' . $item->getBasename('.php');

try {
$reflection = new ReflectionClass($class);
} catch (ReflectionException) {
continue;
}
if (!$reflection->isInstantiable() || !$reflection->isSubclassOf(BakeCommand::class)) {
continue;
}

// Trim off 'Command' from the name.
[$ns, $className] = namespaceSplit($class);
$name = Inflector::underscore(substr((string) $className, 0, -7));

$shortName = $class::defaultName();

if (!empty($shortName)) {
$candidates[$shortName] = $class;
} else {
// Commands ending with `_all` should be ` all` instead.
if (str_ends_with($name, '_all')) {
$name = substr($name, 0, -4) . ' all';
/** @psalm-var class-string<\Bake\Command\BakeCommand> $class */
$class = $namespace . $item->getBasename('.php');

if (!$hasSubfolder) {
try {
$reflection = new ReflectionClass($class);
/** @phpstan-ignore-next-line */
} catch (ReflectionException $e) {
continue;
}
/** @psalm-suppress TypeDoesNotContainType */
if (!$reflection->isInstantiable() || !$reflection->isSubclassOf(BakeCommand::class)) {
continue;
}
$candidates["bake {$name}"] = $class;
}

$candidates[$class::defaultName()] = $class;
}

return $candidates;
Expand Down
Loading

0 comments on commit eef2d11

Please sign in to comment.