Skip to content

Commit ec1541a

Browse files
authored
Add Code Sniffer (#272)
1 parent 3e4e311 commit ec1541a

File tree

4 files changed

+240
-8
lines changed

4 files changed

+240
-8
lines changed

Makefile

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,20 @@ help:
1313
#---------------------------------------------------------------------------
1414

1515
.PHONY: clean
16-
clean: ## Clean all created artifacts
16+
clean: ## Clean all created artifacts
1717
clean:
1818
git clean --exclude=.idea/ -ffdx
1919

20+
.PHONY: cs
21+
CODE_SNIFFER=vendor-bin/code-sniffer/vendor/bin/phpcs
22+
CODE_SNIFFER_FIX=vendor-bin/code-sniffer/vendor/bin/phpcbf
23+
cs: ## Fixes CS
24+
cs: $(CODE_SNIFFER) $(CODE_SNIFFER_FIX)
25+
$(PHPNOGC) $(CODE_SNIFFER_FIX) || true
26+
$(PHPNOGC) $(PHP_CS_FIXER) fix
27+
2028
.PHONY: build
21-
build: ## Build the PHAR
29+
build: ## Build the PHAR
2230
BOX=bin/box
2331
build: bin/php-scoper.phar
2432

@@ -28,26 +36,26 @@ build: bin/php-scoper.phar
2836
#---------------------------------------------------------------------------
2937

3038
.PHONY: test
31-
test: ## Run all the tests
39+
test: ## Run all the tests
3240
test: tc e2e
3341

3442
.PHONY: tu
3543
PHPUNIT=bin/phpunit
36-
tu: ## Run PHPUnit tests
44+
tu: ## Run PHPUnit tests
3745
tu: bin/phpunit
3846
$(PHPBIN) $(PHPUNIT)
3947

4048
.PHONY: tc
41-
tc: ## Run PHPUnit tests with test coverage
49+
tc: ## Run PHPUnit tests with test coverage
4250
tc: bin/phpunit vendor-bin/covers-validator/vendor clover.xml
4351

4452
.PHONY: tm
45-
tm: ## Run Infection (Mutation Testing)
53+
tm: ## Run Infection (Mutation Testing)
4654
tm: bin/phpunit
4755
$(MAKE) e2e_020
4856

4957
.PHONY: e2e
50-
e2e: ## Run end-to-end tests
58+
e2e: ## Run end-to-end tests
5159
e2e: e2e_004 e2e_005 e2e_011 e2e_013 e2e_014 e2e_015 e2e_016 e2e_017 e2e_018 e2e_019 e2e_020 e2e_021 e2e_022 e2e_023 e2e_024 e2e_025 e2e_026 e2e_027
5260

5361
PHPSCOPER=bin/php-scoper.phar
@@ -287,7 +295,7 @@ e2e_027: bin/php-scoper.phar fixtures/set027-laravel/vendor
287295

288296
.PHONY: tb
289297
BLACKFIRE=blackfire
290-
tb: ## Run Blackfire profiling
298+
tb: ## Run Blackfire profiling
291299
tb: bin/php-scoper.phar vendor
292300
$(BLACKFIRE) --new-reference run $(PHPBIN) bin/php-scoper.phar add-prefix --output-dir=build/php-scoper --force --quiet
293301

@@ -314,6 +322,10 @@ vendor-bin/covers-validator/vendor: vendor-bin/covers-validator/composer.lock ve
314322
composer bin covers-validator install
315323
touch $@
316324

325+
vendor-bin/code-sniffer/vendor: vendor-bin/code-sniffer/composer.lock vendor/bamarni
326+
composer bin code-sniffer install
327+
touch $@
328+
317329
fixtures/set005/vendor: fixtures/set005/composer.lock
318330
composer --working-dir=fixtures/set005 install
319331
touch $@
@@ -429,3 +441,11 @@ clover.xml: src
429441
--coverage-clover=clover.xml \
430442
--coverage-xml=dist/infection-coverage/coverage-xml \
431443
--log-junit=dist/infection-coverage/phpunit.junit.xml
444+
445+
$(CODE_SNIFFER): vendor-bin/code-sniffer/vendor
446+
composer bin code-sniffer install
447+
touch $@
448+
449+
$(CODE_SNIFFER_FIX): vendor-bin/code-sniffer/vendor
450+
composer bin code-sniffer install
451+
touch $@

phpcs.xml.dist

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ruleset
3+
name="Doctrine"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:noNamespaceSchemaLocation="vendor-bin/code-sniffer/vendor/squizlabs/php_codesniffer/phpcs.xsd"
6+
>
7+
<arg name="extensions" value="php"/>
8+
<arg name="parallel" value="80"/>
9+
<arg name="cache" value=".phpcs-cache"/>
10+
<arg name="colors"/>
11+
<arg value="ps"/>
12+
13+
<file>fixtures</file>
14+
<exclude-pattern>default_stub\.php</exclude-pattern>
15+
<exclude-pattern>/vendor/</exclude-pattern>
16+
<exclude-pattern>/build/</exclude-pattern>
17+
<file>src</file>
18+
<file>tests</file>
19+
20+
<rule ref="SlevomatCodingStandard.Commenting.InlineDocCommentDeclaration.InvalidFormat"/>
21+
<rule ref="SlevomatCodingStandard.Functions.StaticClosure"/>
22+
<rule ref="SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly.ReferenceViaFallbackGlobalName"/>
23+
<rule ref="SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly.ReferenceViaFullyQualifiedName">
24+
<exclude-pattern>src/bootstrap\.php</exclude-pattern>
25+
<exclude-pattern>src/functions\.php</exclude-pattern>
26+
</rule>
27+
<rule ref="SlevomatCodingStandard.Namespaces.UseDoesNotStartWithBackslash"/>
28+
<rule ref="SlevomatCodingStandard.PHP.OptimizedFunctionsWithoutUnpacking"/>
29+
<rule ref="SlevomatCodingStandard.PHP.TypeCast"/>
30+
<rule ref="SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingReturnTypeHint"/>
31+
</ruleset>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"require-dev": {
3+
"dealerdirect/phpcodesniffer-composer-installer": "^0.5.0",
4+
"slevomat/coding-standard": "^4.8",
5+
"squizlabs/php_codesniffer": "^3.3"
6+
}
7+
}

vendor-bin/code-sniffer/composer.lock

Lines changed: 174 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)