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 Css { |
||
5 | |||
6 | public 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($css){ |
||
20 | if(!is_array($css)) $css = [$css]; |
||
21 | self::$list = array_merge(self::$list,$css); |
||
22 | } |
||
23 | |||
24 | View Code Duplication | public function get(){ |
|
0 ignored issues
–
show
|
|||
25 | $css = array_unique(self::$list); |
||
26 | $code = ''; |
||
27 | foreach($css as $name){ |
||
28 | $file = self::$config['core']['css'].'/'.$name.'.css'; |
||
29 | if(is_file($file)) $code .= file_get_contents($file); |
||
30 | } |
||
31 | $minifier = new \MatthiasMullie\Minify\CSS(); |
||
32 | $minifier->add($code); |
||
33 | $code = $minifier->minify(); |
||
34 | return "<style>$code</style>"; |
||
35 | } |
||
36 | |||
37 | public function compile(){ |
||
38 | # ... |
||
39 | } |
||
40 | |||
41 | } |
||
42 | ?> |
||
43 |
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.