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 |
|
|
|
|
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 |
|
|
|
|
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
|
|
|
|
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.