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.
Passed
Push — master ( 776629...deac27 )
by
unknown
03:03
created

Body::__toString()   C

Complexity

Conditions 12
Paths 31

Size

Total Lines 72
Code Lines 40

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 12
eloc 40
nc 31
nop 0
dl 0
loc 72
rs 6.9666
c 0
b 0
f 0

How to fix   Long Method    Complexity   

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\Framework\Http\Presenter\Assets\Positions;
15
16
// ------------------------------------------------------------------------
17
18
use MatthiasMullie\Minify\JS;
19
use O2System\Framework\Http\Presenter\Assets\Collections;
20
21
/**
22
 * Class Body
23
 *
24
 * @package O2System\Framework\Http\Presenter\Assets\Positions
25
 */
26
class Body extends Abstracts\AbstractPosition
27
{
28
    /**
29
     * Body::$javascript
30
     * 
31
     * @var \O2System\Framework\Http\Presenter\Assets\Collections\Javascript 
32
     */
33
    protected $javascript;
34
35
    // ------------------------------------------------------------------------
36
37
    /**
38
     * Body::__construct
39
     */
40
    public function __construct()
41
    {
42
        $this->javascript = new Collections\Javascript();
43
    }
44
45
    // ------------------------------------------------------------------------
46
47
    /**
48
     * Body::__toString
49
     * 
50
     * @return string
51
     */
52
    public function __toString()
53
    {
54
        $output = [];
55
        $unbundledFilename = ['app', 'app.min', 'theme', 'theme.min'];
56
57
        // Render js
58
        if ($this->javascript->count()) {
59
            foreach($this->javascript as $js) {
60
                if(in_array(pathinfo($js, PATHINFO_FILENAME), $unbundledFilename)) {
61
                    $jsVersion = $this->getVersion($js);
62
                    $output[] = '<script type="text/javascript" src="' . $this->getUrl($js) . '?v=' . $jsVersion . '"></script>';
63
                }
64
            }
65
66
            $bundleJsCollection = $this->javascript->getArrayCopy();
67
            $bundleJsVersion = $this->getVersion(serialize($bundleJsCollection));
68
            $bundleJsFilename = 'body-' . controller()->getClassInfo()->getParameter();
69
            $bundleJsFilePath = PATH_PUBLIC . 'assets' . DIRECTORY_SEPARATOR . 'js' . DIRECTORY_SEPARATOR . $bundleJsFilename . '.js';
70
            $bundleJsMinifyFilePath = PATH_PUBLIC . 'assets' . DIRECTORY_SEPARATOR . 'js' . DIRECTORY_SEPARATOR . $bundleJsFilename . '.min.js';
71
72
            if (is_file($bundleJsFilePath . '.map')) {
73
                $bundleJsMap = json_decode(file_get_contents($bundleJsFilePath . '.map'), true);
74
                // if the file version is changed delete it first
75
                if ( ! hash_equals($bundleJsVersion, $bundleJsMap[ 'version' ])) {
76
                    unlink($bundleJsFilePath);
77
                    unlink($bundleJsFilePath . '.map');
78
                }
79
            }
80
81
            if ( ! is_file($bundleJsFilePath)) {
82
                $bundleJsMap = [
83
                    'version' => $bundleJsVersion,
84
                ];
85
86
                // Create js file
87
                if ($bundleFileStream = @fopen($bundleJsFilePath, 'ab')) {
88
                    flock($bundleFileStream, LOCK_EX);
89
90
                    foreach ($this->css as $css) {
0 ignored issues
show
Bug Best Practice introduced by
The property css does not exist on O2System\Framework\Http\...r\Assets\Positions\Body. Since you implemented __get, consider adding a @property annotation.
Loading history...
91
                        if( ! in_array(pathinfo($css, PATHINFO_FILENAME), $unbundledFilename)) {
92
                            $bundleJsMap[ 'sources' ][] = $css;
93
                            fwrite($bundleFileStream, file_get_contents($css));
94
                        }
95
                    }
96
97
                    flock($bundleFileStream, LOCK_UN);
98
                    fclose($bundleFileStream);
99
                }
100
101
                // Create js map
102
                if ($bundleFileStream = @fopen($bundleJsFilePath . '.map', 'ab')) {
103
                    flock($bundleFileStream, LOCK_EX);
104
105
                    fwrite($bundleFileStream, json_encode($bundleJsMap));
106
107
                    flock($bundleFileStream, LOCK_UN);
108
                    fclose($bundleFileStream);
109
                }
110
111
                // Create js file minify version
112
                $minifyJsHandler = new JS($bundleJsFilePath);
113
                $minifyJsHandler->minify($bundleJsMinifyFilePath);
114
            }
115
116
            if (input()->env('DEBUG_STAGE') === 'PRODUCTION') {
117
                $output[] = '<script type="text/javascript" src="' . $this->getUrl($bundleJsMinifyFilePath) . '?v=' . $bundleJsVersion . '"></script>';
118
            } else {
119
                $output[] = '<script type="text/javascript" src="' . $this->getUrl($bundleJsFilePath) . '?v=' . $bundleJsVersion . '"></script>';
120
            }
121
        }
122
123
        return implode(PHP_EOL, $output);
124
    }
125
}