Completed
Push — master ( c23b73...bac89c )
by Nikita
04:11
created

ParseCss::parse()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 34
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 2
Metric Value
c 2
b 0
f 2
dl 0
loc 34
rs 8.439
cc 5
eloc 14
nc 5
nop 0
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 14 and the first side effect is on line 66.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
/**
3
 * Created by PhpStorm.
4
 * User: ignatenkov_nv
5
 * Date: 27.08.2015
6
 * Time: 15:55
7
 */
8
9
10
/**
11
 * Load img in yandex css
12
 * Class ParseCss
13
 */
14
class ParseCss {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
15
16
    public $dir = "css/";
17
    public $listCss = ['_index.css'];
18
    public $pattern = "/yastatic.net.*.svg/";
19
20
    public $patternFileName = "(yastatic.+\/)([^/]+.\.svg)";
21
    public $patternFileName1 = "/[^/]+.\.svg/";
22
23
    public function parse() {
24
        foreach ($this->listCss as $value) {
25
            //echo $this->getFilePath($value);
0 ignored issues
show
Unused Code Comprehensibility introduced by
78% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
26
            $contents = file_get_contents($this->getFilePath($value));
27
28
            if(preg_match_all($this->pattern, $contents, $matches)){
29
                //echo "Found matches:\n";
30
                //echo implode("\n", $matches[0]);
0 ignored issues
show
Unused Code Comprehensibility introduced by
77% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
31
                foreach ($matches[0] as $val) {
32
33
                    //preg_match($this->patternFileName1, $val, $matc);
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
34
                    //var_dump($matc);
35
                    //echo $val;
36
                    $fileName = basename($val);
37
                    $path = str_replace($fileName, "", $val);
38
                    $path = str_replace("yastatic.net/", "", $path);
39
                    $path = "img/".$path;
40
                    //echo $path . " - " . $fileName."<br>";
0 ignored issues
show
Unused Code Comprehensibility introduced by
43% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
41
42
                    if (!file_exists($path))
43
                        mkdir($path, 0777, true);
44
45
                    $image = file_get_contents("https://".$val);
46
                    file_put_contents($path.$fileName, $image);
47
                }
48
49
                //var_dump($matches);
50
            }
51
52
        }
53
54
        return null;
55
56
    }
57
58
    private function getFilePath($filename) {
59
        return $this->dir.$filename;
60
    }
61
62
63
}
64
65
66
$parse = new ParseCss();
67
$parse->parse();
68