Completed
Push — master ( 518897...538c9f )
by Andrey
03:02 queued 43s
created

Js.php (1 issue)

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 Js {
5
6
    private static $list = [];
7
    private static $host;
8
    private static $config;   
9
10 View Code Duplication
    public function __construct(){
11
        # Config
12
        self::$config = (new Config)->get();
13
        # Host
14
        self::$host = parse_url('http://'.$_SERVER['HTTP_HOST']);
15
        if(isset(self::$host['host'])) self::$host = self::$host['host'];
16
        else self::$host = '/';
17
    }
18
19
    public function add($js){
20
        if(!is_array($js)) $js = [$js];
21
        self::$list = array_merge(self::$list,$js);
22
    }
23
24
    public function get(){
25
        $js = array_unique(self::$list);
26
        if(!empty($js)) $jsQuery = '?'.implode(':',$js);
27
        else $jsQuery = '';
28
        return '<script async src="http://'.self::$host.'/javascript.js'.$jsQuery.'"></script>';
29
    }
30
31 View Code Duplication
    public function compile($query){
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...
32
        $js = $query;
33
        $code = '';
34
        foreach($js as $name){
35
            $file = self::$config['core']['js'].'/'.$name.'.js';
36
            if(is_file($file)) $code .= file_get_contents($file);
37
        }
38
        $minifier = new \MatthiasMullie\Minify\JS();
39
        $minifier->add($code);
40
        $code = $minifier->minify();
41
        return $code;
42
    }
43
44
}
45
?>
46