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.

Library::execute()   B
last analyzed

Complexity

Conditions 7
Paths 21

Size

Total Lines 94
Code Lines 72

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 7
eloc 72
c 1
b 0
f 0
nc 21
nop 0
dl 0
loc 94
rs 7.6775

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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 Library
23
 *
24
 * @package O2System\Reactor\Cli\Commanders\Make
25
 */
26
class Library extends Make
27
{
28
    /**
29
     * Library::$commandDescription
30
     *
31
     * Command description.
32
     *
33
     * @var string
34
     */
35
    protected $commandDescription = 'CLI_MAKE_LIBRARY_DESC';
36
37
    // ------------------------------------------------------------------------
38
39
    /**
40
     * Library::execute
41
     * 
42
     * @throws \ReflectionException
43
     */
44
    public function execute()
45
    {
46
        $this->__callOptions();
47
48
        if (empty($this->optionFilename)) {
49
            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

49
            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...
50
                (new Format())
51
                    ->setContextualClass(Format::DANGER)
52
                    ->setString(language()->getLine('CLI_MAKE_LIBRARY_E_FILENAME'))
53
                    ->setNewLinesAfter(1)
54
            );
55
56
            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...
57
        }
58
59
        if (strpos($this->optionPath, 'Libraries') === false) {
60
            $filePath = $this->optionPath . 'Libraries' . DIRECTORY_SEPARATOR . $this->optionFilename;
61
        } else {
62
            $filePath = $this->optionPath . $this->optionFilename;
63
        }
64
65
        if ( ! is_dir(dirname($filePath))) {
66
            mkdir(dirname($filePath), 0777, true);
67
        }
68
69
        if (is_file($filePath)) {
70
            output()->write(
71
                (new Format())
72
                    ->setContextualClass(Format::DANGER)
73
                    ->setString(language()->getLine('CLI_MAKE_LIBRARY_E_EXISTS', [$filePath]))
74
                    ->setNewLinesAfter(1)
75
            );
76
77
            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...
78
        }
79
80
        $className = prepare_class_name(pathinfo($filePath, PATHINFO_FILENAME));
81
        @list($namespaceDirectory, $subNamespace) = explode('Libraries', dirname($filePath));
82
83
        $classNamespace = loader()->getDirNamespace(
84
                $namespaceDirectory
85
            ) . 'Libraries' . (empty($subNamespace)
86
                ? null
87
                : str_replace(
88
                    '/',
89
                    '\\',
90
                    $subNamespace
91
                )) . '\\';
92
93
        $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...
94
        $vars[ 'NAMESPACE' ] = trim($classNamespace, '\\');
95
        $vars[ 'PACKAGE' ] = '\\' . trim($classNamespace, '\\');
96
        $vars[ 'CLASS' ] = $className;
97
        $vars[ 'FILEPATH' ] = $filePath;
98
99
        $phpTemplate = <<<PHPTEMPLATE
100
<?php
101
/**
102
 * Created by O2System Reactor File Generator.
103
 * DateTime: CREATE_DATETIME
104
 */
105
106
// ------------------------------------------------------------------------
107
108
namespace NAMESPACE;
109
110
// ------------------------------------------------------------------------
111
112
/**
113
 * Class CLASS
114
 *
115
 * @package PACKAGE
116
 */
117
class CLASS
118
{
119
    public function __construct()
120
    {
121
        // TODO: Change the autogenerated stub
122
    }
123
}
124
PHPTEMPLATE;
125
126
        $fileContent = str_replace(array_keys($vars), array_values($vars), $phpTemplate);
127
        file_put_contents($filePath, $fileContent);
128
129
        if (is_file($filePath)) {
130
            output()->write(
131
                (new Format())
132
                    ->setContextualClass(Format::SUCCESS)
133
                    ->setString(language()->getLine('CLI_MAKE_LIBRARY_S_MAKE', [$filePath]))
134
                    ->setNewLinesAfter(1)
135
            );
136
137
            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...
138
        }
139
    }
140
}