This repository was archived by the owner on Jan 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlugin.php
63 lines (53 loc) · 2.27 KB
/
Plugin.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
namespace PHPStyle;
use Composer\Composer;
use Composer\IO\IOInterface;
use Composer\Plugin\PluginInterface;
class Plugin implements PluginInterface
{
public function activate(Composer $composer, IOInterface $io): void
{
$verify_installation = function () {
$root_path = str_replace('\\', '/', getcwd());
$phpstyle_config_file_path = $root_path . '/phpstyle.neon';
if (!file_exists($phpstyle_config_file_path)) {
$phpstyle_neon = <<< 'PHPSTYLE'
parameters:
php: 7.3
risky: false
paths:
- src
- tests
excludePaths:
- src/path/you/want/to/skip
- src/or/a/file-to-skip.php
PHPSTYLE;
file_put_contents($phpstyle_config_file_path, $phpstyle_neon);
}
$php_cs_fixer_dist_file_path = $root_path . '/.php-cs-fixer.dist.php';
if (!file_exists($php_cs_fixer_dist_file_path)) {
$php_cs_fixer_file_content = <<< 'PHPCSFIXER'
/**
* This file was automatically generated by the https://php.style plugin
* to change style settings, modify the phpstyle.neon file.
* https://github.com/jspaetzel/phpstyle
*/
use PHPStyle\PHPStyle;
require_once __DIR__ . '/vendor/autoload.php';
return (new PHPStyle())->getConfig('phpstyle.neon');
PHPCSFIXER;
file_put_contents($php_cs_fixer_dist_file_path, $php_cs_fixer_file_content);
}
};
$composer->getEventDispatcher()->addListener('post-install-cmd', $verify_installation);
$composer->getEventDispatcher()->addListener('post-update-cmd', $verify_installation);
}
public function deactivate(Composer $composer, IOInterface $io): void
{
// At the moment empty; needed for composer 2.x support
}
public function uninstall(Composer $composer, IOInterface $io): void
{
// At the moment empty; needed for composer 2.x support
}
}