GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

Model   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 128
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 78
c 1
b 0
f 0
dl 0
loc 128
rs 10
wmc 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
C execute() 0 98 9
A optionOrm() 0 3 1
1
<?php
2
/**
3
 * This file is part of the O2System PHP Framework package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 *
8
 * @author         Steeve Andrian Salim
9
 * @copyright      Copyright (c) Steeve Andrian Salim
10
 */
11
12
// ------------------------------------------------------------------------
13
14
namespace O2System\Reactor\Cli\Commanders\Make;
15
16
// ------------------------------------------------------------------------
17
18
use O2System\Reactor\Cli\Commanders\Make;
19
use O2System\Kernel\Cli\Writers\Format;
20
21
/**
22
 * Class Model
23
 *
24
 * @package O2System\Reactor\Cli\Commanders\Make
25
 */
26
class Model extends Make
27
{
28
    /**
29
     * Model::$commandDescription
30
     *
31
     * Command description.
32
     *
33
     * @var string
34
     */
35
    protected $commandDescription = 'CLI_MAKE_MODEL_DESC';
36
37
    // ------------------------------------------------------------------------
38
39
    /**
40
     * Model::optionOrm
41
     * 
42
     * @param bool $useOrm
43
     */
44
    public function optionOrm($useOrm = true)
45
    {
46
        $this->isUseORM = $useOrm;
0 ignored issues
show
Bug Best Practice introduced by
The property isUseORM does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
47
    }
48
49
    // ------------------------------------------------------------------------
50
51
    /**
52
     * Model::execute
53
     * 
54
     * @throws \ReflectionException
55
     */
56
    public function execute()
57
    {
58
        $this->__callOptions();
59
60
        if (empty($this->optionFilename)) {
61
            output()->write(
0 ignored issues
show
Bug introduced by
The method write() does not exist on O2System\Kernel\Http\Output. ( Ignorable by Annotation )

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

61
            output()->/** @scrutinizer ignore-call */ write(

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...
62
                (new Format())
63
                    ->setContextualClass(Format::DANGER)
64
                    ->setString(language()->getLine('CLI_MAKE_MODEL_E_FILENAME'))
65
                    ->setNewLinesAfter(1)
66
            );
67
68
            exit(EXIT_ERROR);
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...
69
        }
70
71
        if (strpos($this->optionPath, 'Models') === false) {
72
            $filePath = $this->optionPath . 'Models' . DIRECTORY_SEPARATOR . $this->optionFilename;
73
        } else {
74
            $filePath = $this->optionPath . $this->optionFilename;
75
        }
76
77
        if ( ! is_dir(dirname($filePath))) {
78
            mkdir(dirname($filePath), 0777, true);
79
        }
80
81
        if (is_file($filePath)) {
82
            output()->write(
83
                (new Format())
84
                    ->setContextualClass(Format::DANGER)
85
                    ->setString(language()->getLine('CLI_MAKE_MODEL_E_EXISTS', [$filePath]))
86
                    ->setNewLinesAfter(1)
87
            );
88
89
            exit(EXIT_ERROR);
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...
90
        }
91
92
        $className = prepare_class_name(pathinfo($filePath, PATHINFO_FILENAME));
93
        @list($namespaceDirectory, $subNamespace) = explode('Models', dirname($filePath));
94
95
        $classNamespace = loader()->getDirNamespace(
96
                $namespaceDirectory
97
            ) . 'Models' . (empty($subNamespace)
98
                ? null
99
                : str_replace(
100
                    '/',
101
                    '\\',
102
                    $subNamespace
103
                )) . '\\';
104
105
        $isUseORM = empty($this->isUseORM) ? false : true;
106
107
        $vars[ 'CREATE_DATETIME' ] = date('d/m/Y H:m');
0 ignored issues
show
Comprehensibility Best Practice introduced by
$vars was never initialized. Although not strictly required by PHP, it is generally a good practice to add $vars = array(); before regardless.
Loading history...
108
        $vars[ 'NAMESPACE' ] = trim($classNamespace, '\\');
109
        $vars[ 'PACKAGE' ] = '\\' . trim($classNamespace, '\\');
110
        $vars[ 'CLASS' ] = $className;
111
        $vars[ 'FILEPATH' ] = $filePath;
112
        $vars[ 'EXTEND' ] = $isUseORM
113
            ? 'Orm'
114
            : 'Reactor';
115
116
        $phpTemplate = <<<PHPTEMPLATE
117
<?php
118
/**
119
 * Created by O2System Reactor File Generator.
120
 * DateTime: CREATE_DATETIME
121
 */
122
123
// ------------------------------------------------------------------------
124
125
namespace NAMESPACE;
126
127
// ------------------------------------------------------------------------
128
129
use O2System\Reactor\Models\Sql\Model;
130
131
/**
132
 * Class CLASS
133
 *
134
 * @package PACKAGE
135
 */
136
class CLASS extends Model
137
{
138
    public \$table = 'table_name';
139
}
140
PHPTEMPLATE;
141
142
        $fileContent = str_replace(array_keys($vars), array_values($vars), $phpTemplate);
143
        file_put_contents($filePath, $fileContent);
144
145
        if (is_file($filePath)) {
146
            output()->write(
147
                (new Format())
148
                    ->setContextualClass(Format::SUCCESS)
149
                    ->setString(language()->getLine('CLI_MAKE_MODEL_S_MAKE', [$filePath]))
150
                    ->setNewLinesAfter(1)
151
            );
152
153
            exit(EXIT_SUCCESS);
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...
154
        }
155
    }
156
157
}