TeamScoringRankingUpdateCommand::execute()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 14
rs 9.9666
c 0
b 0
f 0
cc 2
nc 2
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace VideoGamesRecords\CoreBundle\Command\Ranking;
6
7
use Doctrine\ORM\NonUniqueResultException;
8
use Symfony\Component\Console\Attribute\AsCommand;
9
use Symfony\Component\Console\Command\Command;
10
use Symfony\Component\Console\Input\InputInterface;
11
use Symfony\Component\Console\Output\OutputInterface;
12
use Symfony\Component\Lock\LockFactory;
13
use Symfony\Component\Lock\Store\SemaphoreStore;
14
use VideoGamesRecords\CoreBundle\Ranking\Command\ScoringTeamRankingHandler;
15
16
#[AsCommand(
17
    name: 'vgr-core:team-scoring-ranking-update',
18
    description: 'Command to update all team rankings after scroring'
19
)]
20
class TeamScoringRankingUpdateCommand extends Command
21
{
22
    private ScoringTeamRankingHandler $scoringTeamRankingHandler;
23
24
    public function __construct(ScoringTeamRankingHandler $scoringTeamRankingHandler)
25
    {
26
        $this->scoringTeamRankingHandler = $scoringTeamRankingHandler;
27
        parent::__construct();
28
    }
29
30
    /**
31
     * @param InputInterface  $input
32
     * @param OutputInterface $output
33
     * @return int
34
     * @throws NonUniqueResultException
35
     */
36
    protected function execute(InputInterface $input, OutputInterface $output): int
37
    {
38
        $store = new SemaphoreStore();
39
        $factory = new LockFactory($store);
40
41
        $lock = $factory->createLock($this->getName());
0 ignored issues
show
Bug introduced by
It seems like $this->getName() can also be of type null; however, parameter $resource of Symfony\Component\Lock\LockFactory::createLock() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

41
        $lock = $factory->createLock(/** @scrutinizer ignore-type */ $this->getName());
Loading history...
42
43
        if ($lock->acquire()) {
44
            $this->scoringTeamRankingHandler->handle();
45
            $lock->release();
46
        } else {
47
            echo self::$defaultName . " IS LOCKED\n";
48
        }
49
        return Command::SUCCESS;
50
    }
51
}
52