for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Yarak\Console;
use Yarak\Console\Command;
use Yarak\Exceptions\FileNotFound;
use Yarak\Exceptions\InvalidCommand;
class ConsoleKernel
{
/**
* Get all user defined commands.
*
* @return array
*/
public function getCommands()
if (property_exists($this, 'commands')) {
return array_map(function ($command) {
$this->verifyCommand($command);
return $command;
}, $this->commands);
commands
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
class MyClass { } $x = new MyClass(); $x->foo = true;
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:
class MyClass { public $foo; } $x = new MyClass(); $x->foo = true;
}
* Verify user defined commands.
* @param string $command
* @throws FileNotFound|InvalidCommand
protected function verifyCommand($command)
if (!class_exists($command)) {
throw FileNotFound::commandNotFound($command);
$class = new $command();
if (!is_a($class, Command::class)) {
throw InvalidCommand::doesntExtendCommand();
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: