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 ( e8b027...c00205 )
by Beñat
09:31
created

Hooks   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 62
Duplicated Lines 45.16 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 3
Bugs 0 Features 1
Metric Value
wmc 13
c 3
b 0
f 1
lcom 1
cbo 5
dl 28
loc 62
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A addHooks() 14 14 3
A buildDistFile() 14 14 3
B addFiles() 0 19 5
A rootDir() 0 4 1
A lin3sCsRootDir() 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
declare(strict_types=1);
13
14
namespace LIN3S\CS\Composer;
15
16
use LIN3S\CS\Application;
17
use LIN3S\CS\Checker\EsLint;
18
use LIN3S\CS\Checker\PhpCsFixer;
19
use LIN3S\CS\Checker\Stylelint;
20
use Symfony\Component\Filesystem\Filesystem;
21
22
/**
23
 * @author Beñat Espiña <[email protected]>
24
 */
25
final class Hooks
26
{
27 View Code Duplication
    public static function addHooks() : void
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...
28
    {
29
        $hooksDirectory = self::rootDir() . '/.git/hooks';
30
        $fileSystem = new Filesystem();
31
32
        try {
33
            if ($fileSystem->exists($hooksDirectory)) {
34
                $fileSystem->remove($hooksDirectory);
35
            }
36
            $fileSystem->symlink(__DIR__ . '/../Hooks', $hooksDirectory, true);
37
        } catch (\Exception $exception) {
38
            echo sprintf("Something wrong happens during the symlink process: \n%s\n", $exception->getMessage());
39
        }
40
    }
41
42 View Code Duplication
    public static function buildDistFile() : void
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...
43
    {
44
        $distFile = self::rootDir() . '/.lin3s_cs.yml.dist';
45
        $fileSystem = new Filesystem();
46
47
        try {
48
            if ($fileSystem->exists($distFile)) {
49
                return;
50
            }
51
            $fileSystem->copy(self::lin3sCsRootDir() . '/.lin3s_cs.yml.dist', $distFile);
52
        } catch (\Exception $exception) {
53
            echo sprintf("Something wrong happens during the touch process: \n%s\n", $exception->getMessage());
54
        }
55
    }
56
57
    public static function addFiles() : void
58
    {
59
        $app = new Application();
60
        $enabled = $app->parameters()['enabled'] ?? [];
61
62
        !in_array('stylelint', $enabled, true) ?: Stylelint::file($app->parameters());
63
        !in_array('eslint', $enabled, true) ?: EsLint::file($app->parameters());
64
        !in_array('phpcsfixer', $enabled, true) ?: PhpCsFixer::file($app->parameters());
65
66
        $editorConfig = self::rootDir() . '/.editorconfig';
67
        $fileSystem = new Filesystem();
68
69
        try {
70
            $fileSystem->remove($editorConfig);
71
            $fileSystem->symlink(self::lin3sCsRootDir() . '/.editorconfig', $editorConfig, true);
72
        } catch (\Exception $exception) {
73
            echo sprintf("Something wrong happens during the symlink process: \n%s\n", $exception->getMessage());
74
        }
75
    }
76
77
    private static function rootDir() : string
78
    {
79
        return __DIR__ . '/../../../../../../..';
80
    }
81
82
    private static function lin3sCsRootDir() : string
83
    {
84
        return __DIR__ . '/../..';
85
    }
86
}
87