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.
Completed
Push — master ( d7e77a...de0430 )
by Beñat
04:49
created

ScssLint   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 59
Duplicated Lines 57.63 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 0
Metric Value
wmc 9
c 0
b 0
f 0
lcom 1
cbo 6
dl 34
loc 59
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
B check() 18 31 6
A file() 16 16 2
A location() 0 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
/*
4
 * This file is part of the CS library.
5
 *
6
 * Copyright (c) 2015-present LIN3S <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace LIN3S\CS\Checker;
13
14
use LIN3S\CS\Error\Error;
15
use Symfony\Component\Filesystem\Filesystem;
16
use Symfony\Component\Process\Process;
17
use Symfony\Component\Yaml\Yaml;
18
19
/**
20
 * @author Beñat Espiña <[email protected]>
21
 */
22
final class ScssLint implements Checker
23
{
24
    use FileFinder;
25
    use ToolAvailability;
26
27
    public static function check(array $files = [], array $parameters = null)
28
    {
29
        self::isAvailable('scss-lint');
30
        self::file($parameters);
31
        $excludes = [];
32
        foreach ($parameters['scsslint_exclude'] as $key => $exclude) {
33
            $excludes[$key] = $parameters['scsslint_path'] . '/' . $exclude;
34
        }
35
36
        $errors = [];
37 View Code Duplication
        foreach ($files as $file) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
38
            if (false === self::exist($file, $parameters['scsslint_path'], 'scss') || in_array($file, $excludes)) {
39
                continue;
40
            }
41
42
            $process = new Process(
43
                sprintf('scss-lint %s -c %s/.scss_lint.yml', $file, self::location($parameters)),
44
                $parameters['root_directory']
45
            );
46
            $process->run();
47
            if (!$process->isSuccessful()) {
48
                $errors[] = new Error(
49
                    $file,
50
                    sprintf('<error>%s</error>', trim($process->getErrorOutput())),
51
                    sprintf('<error>%s</error>', trim($process->getOutput()))
52
                );
53
            }
54
        }
55
56
        return $errors;
57
    }
58
59 View Code Duplication
    public static function file($parameters)
0 ignored issues
show
Duplication introduced by
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...
60
    {
61
        $yaml = array_replace_recursive(
62
            Yaml::parse(file_get_contents(__DIR__ . '/../.scss_lint.yml.dist')), $parameters['scsslint_rules']
63
        );
64
        $location = self::location($parameters) . '/.scss_lint.yml';
65
        $fileSystem = new Filesystem();
66
67
        try {
68
            $fileSystem->remove($location);
69
            $fileSystem->touch($location);
70
            file_put_contents($location, Yaml::dump($yaml));
71
        } catch (\Exception $exception) {
72
            echo sprintf("Something wrong happens during the creating process: \n%s\n", $exception->getMessage());
73
        }
74
    }
75
76
    private static function location($parameters)
77
    {
78
        return $parameters['root_directory'] . '/' . $parameters['scsslint_file_location'];
79
    }
80
}
81