Passed
Push — master ( 083ff7...c84473 )
by William
03:02
created

SyncGithubIssueStatesShell::buildOptionParser()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 5
ccs 3
cts 3
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Sync Github issue states Shell.
5
 *
6
 * phpMyAdmin Error reporting server
7
 * Copyright (c) phpMyAdmin project (https://www.phpmyadmin.net/)
8
 *
9
 * Licensed under The MIT License
10
 * For full copyright and license information, please see the LICENSE.txt
11
 * Redistributions of files must retain the above copyright notice.
12
 *
13
 * @copyright Copyright (c) phpMyAdmin project (https://www.phpmyadmin.net/)
14
 * @license   https://opensource.org/licenses/mit-license.php MIT License
15
 *
16
 * @see      https://www.phpmyadmin.net/
17
 */
18
19
namespace App\Shell;
20
21
use App\Application;
22
use Cake\Command\Command;
23
use Cake\Console\Arguments;
24
use Cake\Console\ConsoleIo;
25
use Cake\Console\ConsoleOptionParser;
26
use Cake\Core\Configure;
27
use Cake\Http\ServerRequest;
28
use Cake\Log\Log;
29
use const PHP_SAPI;
30
use function date;
31
32
/**
33
 * Sync Github issue states Shell.
34
 */
35
class SyncGithubIssueStatesShell extends Command
36
{
37
    protected const NAME = 'sync_github_issue_states';
38
39
    /**
40
     * The name of this command.
41
     *
42
     * @var string
43
     */
44
    protected $name = self::NAME;
45
46 21
    public static function defaultName(): string
47
    {
48 21
        return self::NAME;
49
    }
50
51 7
    protected function buildOptionParser(ConsoleOptionParser $parser): ConsoleOptionParser
52
    {
53
        return $parser
54 7
            ->setCommand($this->name)
55 7
            ->setDescription('Sync GitHub issues states');
56
    }
57
58 7
    public function execute(Arguments $args, ConsoleIo $io)
59
    {
60 7
        Log::debug(
61
            'STARTED: Job "'
62
                . 'github/sync_issue_status'
63
                . '" at '
64 7
                . date('d-m-Y G:i:s (e)'),
65 7
            ['scope' => 'cron_jobs']
66
        );
67
68 7
        Configure::write('CronDispatcher', true);
69 7
        if (PHP_SAPI !== 'cli') {
70
            exit;
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
71
        }
72
73 7
        $request = new ServerRequest([
74 7
            'url' => '/github/sync_issue_status',
75
            'params' => [
76
                'controller' => 'Github',
77
                'action' => 'sync_issue_status',
78
            ],
79
        ]);
80
81 7
        $server = new Application('');
82 7
        $server->handle($request);
83
84 7
        Log::debug(
85
            'FINISHED: Job "'
86
                . 'github/sync_issue_status'
87
                . '" at '
88 7
                . date('d-m-Y G:i:s (e)'),
89 7
            ['scope' => 'cron_jobs']
90
        );
91 7
    }
92
}
93