Completed
Push — master ( ffee62...1450e2 )
by Andrey
03:08
created

Content.php (6 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
namespace humanity;
3
4
class Content {
5
6
    private static $host;
0 ignored issues
show
The property $host is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
7
    private static $path;
8
    private static $config; 
9
    private static $js;
10
    private static $css;
11
    private static $app;
12
    private static $view;
13
    private static $widget;
14
    private static $title;
15
    private static $description;
16
    private static $keywords;
17
    private static $uri;
18
19 View Code Duplication
    public function __construct(){
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
20
        # Config
21
        self::$config = (new Config)->get();
22
        # Application
23
        self::$app = new Application;
24
        # View
25
        self::$view = new View;
26
        # Widget
27
        self::$widget = new Widget;
28
        # Js
29
        self::$js = new Js;
30
        # Css
31
        self::$css = new Css;
32
        # Title
33
        self::$title = new Title;
34
        # Desctiption
35
        self::$description = new Description;
36
        # Keywords
37
        self::$keywords = new Keywords;
38
        # Uri
39
        self::$uri = new Uri;
40
    }
41
42
    public function view($name){
43
        $file = $this->file($name);
44
        if(is_file($file)) require $file;
45
    }
46
47
    public function page(){
48
        # get file
49
        $file = $this->file();
50
        # get content
51
        ob_start();
52
        require $file;
53
        $content = ob_get_clean();
54
        # get css
55
        $css = self::$css->get();
56
        # get css
57
        $js = self::$js->get();
58
        # get title
59
        $title = self::$title->get();
60
        # get description
61
        $description = self::$description->get();
62
        # get keywords
63
        $keywords = self::$keywords->get();
64
        # include for page
65
        $content = preg_replace('/<head>/',"<head>$keywords",$content);
66
        $content = preg_replace('/<head>/',"<head>$description",$content);
67
        $content = preg_replace('/<head>/',"<head>$title",$content);
68
        $content = preg_replace('/<\/head>/',"$css</head>",$content);
69
        $content = preg_replace('/<\/body>/',"$js</body>",$content);
70
        $minify = new MinifyHTML($content);
71
        $content = $minify->compress();
72
        echo $content;
73
    }
74
75
    public function js($query){
76
        echo self::$js->compile($query);
77
    }
78
79
    # $type - page,view
80
    public function file($name=false){
81
        if($name === false){
82
            $path = self::$config['core']['page'];
83
        } else {
84
            $path = self::$config['core']['view'].'/'.$name;
85
        }
86
        # Route
87
        $uri = self::$path;
88
        array_push($uri,'');
89
        foreach($uri as $key=>$value){ if(empty(trim($value))) { unset($uri[$key]); continue; } }
90
        $uri = array_values($uri);
91
        $isFile = null;
0 ignored issues
show
$isFile is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
92
        $currentUri = null;
0 ignored issues
show
$currentUri is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
93
        $filePhtml = null;
94
        for($i=count($uri)-1; $i>=0; $i--){
95
          $nextUri = implode('/',array_slice($uri,0,$i+1));
96
          $getFile = function($type) use($path,$nextUri){
97
            $file = $path.'/'.$nextUri.'/index.'.$type;
98
            if(is_file($file)) return $file;
99
            return null;
100
          };
101
          $filePhtml = $getFile('phtml');
102
          if($filePhtml) { $currentUri = $nextUri; break; }
0 ignored issues
show
$currentUri is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
103
        }
104
        if($filePhtml === null) {
105
          $filePhtml = $path.'/index.phtml';
106
        }
107
        return $filePhtml;
108
    }
109
110
}
111
?>
0 ignored issues
show
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...
112