Skip to content

Commit f683233

Browse files
authored
Merge pull request #12 from YouweGit/feature/split-grumphp-config-templates
Split out grumphp configuration into magento2 and pimcore options
2 parents 61155f4 + 78baa90 commit f683233

File tree

10 files changed

+145
-4
lines changed

10 files changed

+145
-4
lines changed

CHANGELOG.md

+16
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,22 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## 2.15.0
8+
### Added
9+
- Project type resolver can now look for pimcore projects.
10+
- Pimcore projects have their own [git blacklist](docs/components/git-blacklist.md) configuration.
11+
- In the future, the pimcore coding standard will have its own package for `phpcs.xml` and `phpmd.xml` rulesets.
12+
- `grumphp.yml` file for `pimcore` projects.
13+
- This file falls back on the default configuration and inherits all properties, except for the blacklist triggers.
14+
- [Git blacklist](docs/components/git-blacklist.md) documentation.
15+
16+
### Changed
17+
- The magento2 `grumphp.yml` file is split off from the default configuration.
18+
- The `grumphp.yml` that's part of a project will automatically point to the new magento2-specific config file.
19+
- The new file falls back on the default configuration, and overrides the git blacklist keywords and triggers.
20+
- The magento specific constructs are also removed from the default `grumphp.yml` template.
21+
- The default `phpcs.xml` file now references a relative ruleset instead of an absolute path.
22+
723
## 2.14.0
824
### Added
925
- New pathing for `phpcs.xml` file.

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@ predefined default configurations per project type.
2020
- Laravel (`laravel`)
2121
- [Magento 1](docs/project-types/magento1.md) (`magento1`)
2222
- [Magento 2](docs/project-types/magento2.md) (`magento2`)
23+
- Pimcore (`pimcore`)
2324

2425
## Included analysis tools
2526

27+
- [Git blacklist](docs/components/git-blacklist.md)
2628
- [Composer file validation](docs/components/composer.md)
2729
- [JSON Lint](docs/components/jsonlint.md)
2830
- [YamlLint](docs/components/yamllint.md)

config/default/grumphp.yml

+10-2
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,19 @@ parameters:
4545

4646
git_blacklist.keywords:
4747
- "die("
48+
- "dd("
4849
- "var_dump("
50+
- "console.log("
51+
- "alert("
52+
- "print_r("
53+
- "phpinfo("
4954
- "exit;"
50-
- "Magento\\\\Framework\\\\App\\\\ObjectManager"
55+
- "<<<<<"
56+
- ">>>>>"
57+
- "====="
58+
- "<?php echo"
59+
git_blacklist.triggered_by: [ 'php', 'js' ]
5160
git_blacklist.whitelist_patterns: []
52-
git_blacklist.triggered_by: [ 'php' ]
5361
git_blacklist.regexp_type: G
5462
git_blacklist.match_word: false
5563

config/magento2/grumphp.yml

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
imports:
2+
- resource: '../default/grumphp.yml'
3+
4+
# Extend git blacklist and triggers with Magento constructs
5+
parameters:
6+
git_blacklist.keywords:
7+
- "die("
8+
- "dd("
9+
- "var_dump("
10+
- "console.log("
11+
- "alert("
12+
- "print_r("
13+
- "phpinfo("
14+
- "exit;"
15+
- "<<<<<"
16+
- ">>>>>"
17+
- "====="
18+
- "<?php echo"
19+
- "Magento\\\\Framework\\\\App\\\\ObjectManager"
20+
git_blacklist.triggered_by: [ 'php', 'js', 'phtml' ]

config/pimcore/grumphp.yml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
imports:
2+
- resource: '../default/grumphp.yml'
3+
4+
# Extend git triggers with common pimcore constructs
5+
parameters:
6+
git_blacklist.triggered_by: [ 'php', 'js', 'twig' ]

docs/components/git-blacklist.md

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# Git commit keyword validation
2+
3+
## Purpose
4+
Every commit, blacklisted phrases are scanned within scanned files containing a specified file extension.\
5+
The purpose of these checks is to prevent committing production-breaking or sensative system information.
6+
7+
## Keywords used
8+
**_Note:_** some example configuration is below. Specific packages might override the default configuration.
9+
10+
To prevent accidental commits of specific syntax that may cause issues, the testing suite sniffs\
11+
several keywords in your commits.
12+
13+
### Preventing production logs, debug statements and leaking sensitive system information
14+
```yaml
15+
- "die("
16+
- "dd("
17+
- "var_dump("
18+
- "console.log("
19+
- "alert("
20+
- "print_r("
21+
- "phpinfo("
22+
```
23+
24+
### Preventing accidental committing of merge conflicts
25+
```yaml
26+
- "<<<<<"
27+
- ">>>>>"
28+
- "====="
29+
```
30+
31+
### Preventing statements that have better alternatives
32+
```yaml
33+
- "<?php echo"
34+
```
35+
36+
* The magento2 coding standards extend this with invocation of the ObjectManager.
37+
38+
## Files scanned
39+
The following files are scanned for blacklisted keywords in a default configuration.
40+
41+
**_Note:_** different project types might override the files scanned.
42+
```yaml
43+
- .php
44+
- .js
45+
```
46+
* Magento2 project types extend this with .phtml files.
47+
* Pimcore project types extend this with .twig files.
48+
49+
## Override the configuration
50+
To override the default git blacklist with your own, override the configuration in the `grumphp.yml` file\
51+
in your local project. An example configuration can be found below.
52+
53+
Full details of available configuration options can be found [here](https://github.com/phpro/grumphp/blob/master/doc/tasks/git_blacklist.md).
54+
55+
Note: configuration keys are **overwritten, not merged**.
56+
57+
```yaml
58+
imports:
59+
- resource: 'vendor/youwe/testing-suite/config/default/grumphp.yml'
60+
61+
parameters:
62+
git_blacklist.keywords:
63+
- "die("
64+
- "dd("
65+
- "var_dump("
66+
- "console.log("
67+
- "alert("
68+
- "print_r("
69+
- "phpinfo("
70+
- "exit;"
71+
- "<<<<<"
72+
- ">>>>>"
73+
- "====="
74+
- "<?php echo"
75+
- "My additional keyword"
76+
git_blacklist.triggered_by: [ 'php', 'js', 'additional_file_extension_here' ]
77+
```

src/Installer/FilesInstaller.php

+10-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ private function resolveYouwePathing(FileMappingInterface $unixFileMapping): voi
8080
{
8181
$name = $unixFileMapping->getRelativeDestination();
8282

83-
if ($this->mappingResolver->getTypeResolver()->resolve() === 'magento2' && !in_array($name, ['grumphp.yml'])) {
83+
if ($this->mappingResolver->getTypeResolver()->resolve() === 'magento2') {
8484
if ($name === "phpcs.xml") {
8585
$this->updatePath(
8686
$unixFileMapping->getDestination(),
@@ -101,6 +101,15 @@ private function resolveYouwePathing(FileMappingInterface $unixFileMapping): voi
101101
],
102102
'./vendor/youwe/coding-standard-magento2/src/YouweMagento2/phpmd.xml'
103103
);
104+
} elseif ($name === "grumphp.yml") {
105+
$this->updatePath(
106+
$unixFileMapping->getDestination(),
107+
[
108+
'vendor/mediact/testing-suite/config/default/grumphp.yml',
109+
'vendor/youwe/testing-suite/config/default/grumphp.yml'
110+
],
111+
'vendor/youwe/testing-suite/config/magento2/grumphp.yml'
112+
);
104113
}
105114
} elseif ($this->mappingResolver->getTypeResolver()->resolve() === 'magento') {
106115
if ($name === "phpcs.xml") {

src/ProjectTypeResolver.php

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class ProjectTypeResolver
4040
'magento-project' => 'magento2',
4141
'alumio-project' => 'alumio',
4242
'laravel-project' => 'laravel',
43+
'pimcore-project' => 'pimcore'
4344
];
4445

4546
public const DEFAULT_PROJECT_TYPE = 'default';

templates/files/default/phpcs.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd">
77
<description>PHPCS</description>
88
<!--<exclude-pattern>path/to/exclude/*</exclude-pattern>-->
9-
<rule ref="./vendor/youwe/coding-standard/src/Youwe"/>
9+
<rule ref="Youwe"/>
1010
<!-- Append arg -s to phpcs to display the name of failed sniffs -->
1111
<arg value="s"/>
1212
</ruleset>

templates/files/pimcore/grumphp.yml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
imports:
2+
- resource: 'vendor/youwe/testing-suite/config/pimcore/grumphp.yml'

0 commit comments

Comments
 (0)