Completed
Push — master ( deb1d5...3324ab )
by Pablo
04:13
created

src/PhpGitHooks/Infrastructure/Hook/PreCommit.php (3 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace PhpGitHooks\Infrastructure\Hook;
4
5
require_once __DIR__.'/../../../../app/AppKernel.php';
6
7
use AppKernel;
8
use PhpGitHooks\Module\Git\Contract\Command\PreCommitToolCommand;
9
use PhpGitHooks\Module\Git\Contract\CommandHandler\PreCommitToolCommandHandler;
10
use Symfony\Component\Console\Application;
11
use Symfony\Component\Console\Input\InputInterface;
12
use Symfony\Component\Console\Output\OutputInterface;
13
14
/**
15
 * Class PreCommit.
16
 *
17
 * @codingStandardsIgnoreFile
18
 */
19 View Code Duplication
class PreCommit extends Application
0 ignored issues
show
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
20
{
21
    /**
22
     * @var AppKernel
23
     */
24
    private $container;
25
26
    /**
27
     * PreCommit constructor.
28
     */
29
    public function __construct()
30
    {
31
        $appKernel = new AppKernel('dev', true);
32
        $appKernel->boot();
33
        $this->container = $appKernel->getContainer();
0 ignored issues
show
Documentation Bug introduced by
It seems like $appKernel->getContainer() can also be of type object<Symfony\Component...ion\ContainerInterface>. However, the property $container is declared as type object<AppKernel>. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
34
        parent::__construct('pre-commit');
35
    }
36
37
    public function doRun(InputInterface $input, OutputInterface $output)
38
    {
39
        /**
40
         * @var PreCommitToolCommandHandler
41
         */
42
        $command = $this->container->get('bruli.command.bus');
0 ignored issues
show
The method get() does not seem to exist on object<AppKernel>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
43
        $command->handle(new PreCommitToolCommand());
44
    }
45
}
46