Skip to content

Commit d086b1b

Browse files
committed
[WIP] Add PHPStan 0.11 compatibility and add CI tests
Update extension to work with PHPStan 0.11 and add a travis configuration that executes linters and (phpstan) tests against the extension code via phing Closes #7
1 parent bd61028 commit d086b1b

17 files changed

+651
-483
lines changed

.editorconfig

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
root = true
2+
3+
[*]
4+
end_of_line = lf
5+
insert_final_newline = true
6+
charset = utf-8
7+
trim_trailing_whitespace = true
8+
9+
[*.{php,phpt}]
10+
indent_style = tab
11+
indent_size = 4
12+
13+
[*.xml]
14+
indent_style = tab
15+
indent_size = 4
16+
17+
[*.neon]
18+
indent_style = tab
19+
indent_size = 4
20+
21+
[*.{yaml,yml}]
22+
indent_style = space
23+
indent_size = 2
24+
25+
[composer.json]
26+
indent_style = tab
27+
indent_size = 4

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
1-
/vendor
21
/composer.lock
2+
/vendor
3+
/typo3
4+
/.idea
5+
/index.php

build.xml

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<project name="PHPStan TYPO3 extensions" default="check">
3+
<target name="check" depends="
4+
composer,
5+
lint,
6+
cs,
7+
phpstan
8+
"/>
9+
10+
<target name="composer">
11+
<exec
12+
executable="composer"
13+
logoutput="true"
14+
passthru="true"
15+
checkreturn="true"
16+
>
17+
<arg value="install"/>
18+
</exec>
19+
</target>
20+
21+
<target name="lint">
22+
<exec
23+
executable="vendor/bin/parallel-lint"
24+
logoutput="true"
25+
passthru="true"
26+
checkreturn="true"
27+
>
28+
<arg path="src" />
29+
</exec>
30+
</target>
31+
32+
<target name="cs">
33+
<exec
34+
executable="vendor/bin/phpcs"
35+
logoutput="true"
36+
passthru="true"
37+
checkreturn="true"
38+
>
39+
<arg value="--extensions=php"/>
40+
<arg value="--encoding=utf-8"/>
41+
<arg value="--tab-width=4"/>
42+
<arg value="-sp"/>
43+
<arg path="src"/>
44+
</exec>
45+
</target>
46+
47+
<target name="cs-fix">
48+
<exec
49+
executable="vendor/bin/phpcbf"
50+
logoutput="true"
51+
passthru="true"
52+
checkreturn="true"
53+
>
54+
<arg value="--extensions=php"/>
55+
<arg value="--encoding=utf-8"/>
56+
<arg value="--tab-width=4"/>
57+
<arg value="-sp"/>
58+
<arg path="src"/>
59+
</exec>
60+
</target>
61+
62+
<target name="phpstan">
63+
<exec
64+
executable="vendor/bin/phpstan"
65+
logoutput="true"
66+
passthru="true"
67+
checkreturn="true"
68+
>
69+
<arg value="analyse"/>
70+
<arg value="-l"/>
71+
<arg value="7"/>
72+
<arg value="-c"/>
73+
<arg path="phpstan.neon"/>
74+
<arg path="src"/>
75+
</exec>
76+
</target>
77+
</project>

composer.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,17 @@
77
"prefer-stable": true,
88
"require": {
99
"php": "~7.1",
10-
"phpstan/phpstan": "^0.10",
10+
"phpstan/phpstan": "^0.11",
1111
"typo3/cms-core": "^8.7 || ^9.5",
1212
"typo3/cms-extbase": "^8.7 || ^9.5"
1313
},
14+
"require-dev": {
15+
"consistence/coding-standard": "^3.8",
16+
"dealerdirect/phpcodesniffer-composer-installer": "^0.4.4",
17+
"jakub-onderka/php-parallel-lint": "^1.0",
18+
"phing/phing": "^2.16.0",
19+
"phpstan/phpstan-strict-rules": "^0.11"
20+
},
1421
"suggest": {
1522
"typo3/testing-framework": "Testing framework is used in the bootstrap (src/PhpStanTypo3Bootstrap.php). In most cases you need this package but you may also use your custom bootstrap (e.g. if you use nimut/testing-framework)"
1623
},

extension.neon

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
parameters:
2+
bootstrap: ./src/PhpStanTypo3Bootstrap.php
3+
14
services:
25
-
36
class: SaschaEgerer\PhpstanTypo3\Reflection\RepositoryMethodsClassReflectionExtension

phpcs.xml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?xml version="1.0"?>
2+
<ruleset name="PHPStan Doctrine">
3+
<rule ref="vendor/consistence/coding-standard/Consistence/ruleset.xml">
4+
<exclude name="Squiz.Functions.GlobalFunction.Found"/>
5+
<exclude name="SlevomatCodingStandard.Namespaces.FullyQualifiedClassNameAfterKeyword"/>
6+
<exclude name="SlevomatCodingStandard.Namespaces.FullyQualifiedClassNameInAnnotation"/>
7+
<exclude name="SlevomatCodingStandard.Namespaces.FullyQualifiedExceptions"/>
8+
<exclude name="SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly"/>
9+
<exclude name="Consistence.Exceptions.ExceptionDeclaration"/>
10+
</rule>
11+
<rule ref="SlevomatCodingStandard.Namespaces.AlphabeticallySortedUses">
12+
<properties>
13+
<property name="caseSensitive" value="false"/>
14+
</properties>
15+
</rule>
16+
<rule ref="SlevomatCodingStandard.TypeHints.DeclareStrictTypes">
17+
<properties>
18+
<property name="newlinesCountBetweenOpenTagAndDeclare" value="0"/>
19+
</properties>
20+
</rule>
21+
<rule ref="SlevomatCodingStandard.TypeHints.TypeHintDeclaration">
22+
<properties>
23+
<property name="enableObjectTypeHint" value="false"/>
24+
</properties>
25+
</rule>
26+
<rule ref="SlevomatCodingStandard.ControlStructures.AssignmentInCondition"/>
27+
<rule ref="SlevomatCodingStandard.Operators.DisallowEqualOperators"/>
28+
<rule ref="SlevomatCodingStandard.ControlStructures.EarlyExit"/>
29+
<rule ref="SlevomatCodingStandard.Classes.SuperfluousAbstractClassNaming"/>
30+
<rule ref="SlevomatCodingStandard.Classes.SuperfluousInterfaceNaming"/>
31+
</ruleset>

phpstan.neon

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
1+
includes:
2+
- vendor/phpstan/phpstan-strict-rules/rules.neon
13
parameters:
2-
bootstrap: src/PhpStanTypo3Bootstrap.php
4+
excludes_analyse:
5+
- src/PhpstanTypo3Bootstrap.php

src/PhpstanTypo3Bootstrap.php

Lines changed: 44 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,51 @@
1-
<?php
1+
<?php declare(strict_types = 1);
22

3-
call_user_func(function () {
4-
$testbase = new \TYPO3\TestingFramework\Core\Testbase();
5-
$testbase->enableDisplayErrors();
6-
$testbase->defineBaseConstants();
7-
$testbase->defineSitePath();
8-
$testbase->defineTypo3ModeBe();
9-
$testbase->setTypo3TestingContext();
10-
$testbase->definePackagesPath();
11-
$testbase->createDirectory(PATH_site . 'typo3conf/ext');
12-
$testbase->createDirectory(PATH_site . 'typo3temp/assets');
13-
$testbase->createDirectory(PATH_site . 'typo3temp/var/tests');
14-
$testbase->createDirectory(PATH_site . 'typo3temp/var/transient');
15-
$testbase->createDirectory(PATH_site . 'uploads');
3+
// phpcs:disable PSR1.Files.SideEffects
4+
call_user_func(function (): void {
5+
// disable TYPO3_DLOG
6+
define('TYPO3_DLOG', false);
167

17-
// disable TYPO3_DLOG
18-
define('TYPO3_DLOG', false);
8+
$testbase = new \TYPO3\TestingFramework\Core\Testbase();
9+
$testbase->enableDisplayErrors();
10+
$testbase->defineBaseConstants();
11+
$testbase->defineSitePath();
12+
$testbase->defineTypo3ModeBe();
13+
$testbase->setTypo3TestingContext();
14+
$testbase->definePackagesPath();
15+
$testbase->createDirectory(PATH_site . 'typo3conf/ext');
16+
$testbase->createDirectory(PATH_site . 'typo3temp/assets');
17+
$testbase->createDirectory(PATH_site . 'typo3temp/var/tests');
18+
$testbase->createDirectory(PATH_site . 'typo3temp/var/transient');
19+
$testbase->createDirectory(PATH_site . 'uploads');
1920

20-
// Retrieve an instance of class loader and inject to core bootstrap
21-
$classLoaderFilepath = TYPO3_PATH_PACKAGES . 'autoload.php';
22-
if (!file_exists($classLoaderFilepath)) {
23-
die('ClassLoader can\'t be loaded. Please check your path or set an environment variable \'TYPO3_PATH_ROOT\' to your root path.');
24-
}
25-
$classLoader = require $classLoaderFilepath;
26-
\TYPO3\CMS\Core\Core\Bootstrap::getInstance()
27-
->initializeClassLoader($classLoader)
28-
->setRequestType(TYPO3_REQUESTTYPE_BE | TYPO3_REQUESTTYPE_CLI)
29-
->baseSetup();
21+
// Retrieve an instance of class loader and inject to core bootstrap
22+
$classLoaderFilepath = TYPO3_PATH_PACKAGES . 'autoload.php';
23+
if (!file_exists($classLoaderFilepath)) {
24+
die('ClassLoader can\'t be loaded. Please check your path or set an environment variable \'TYPO3_PATH_ROOT\' to your root path.');
25+
}
26+
$classLoader = require $classLoaderFilepath;
27+
\TYPO3\CMS\Core\Core\Bootstrap::getInstance()
28+
->initializeClassLoader($classLoader)
29+
->setRequestType(TYPO3_REQUESTTYPE_BE | TYPO3_REQUESTTYPE_CLI)
30+
->baseSetup();
3031

31-
// Initialize default TYPO3_CONF_VARS
32-
$configurationManager = new \TYPO3\CMS\Core\Configuration\ConfigurationManager();
33-
$GLOBALS['TYPO3_CONF_VARS'] = $configurationManager->getDefaultConfiguration();
34-
// Avoid failing tests that rely on HTTP_HOST retrieval
35-
$GLOBALS['TYPO3_CONF_VARS']['SYS']['trustedHostsPattern'] = '.*';
32+
// Initialize default TYPO3_CONF_VARS
33+
$configurationManager = new \TYPO3\CMS\Core\Configuration\ConfigurationManager();
34+
$GLOBALS['TYPO3_CONF_VARS'] = $configurationManager->getDefaultConfiguration();
35+
// Avoid failing tests that rely on HTTP_HOST retrieval
36+
$GLOBALS['TYPO3_CONF_VARS']['SYS']['trustedHostsPattern'] = '.*';
3637

37-
\TYPO3\CMS\Core\Core\Bootstrap::getInstance()
38-
->disableCoreCache()
39-
->initializeCachingFramework()
40-
// Set all packages to active
41-
->initializePackageManagement(\TYPO3\CMS\Core\Package\UnitTestPackageManager::class);
38+
\TYPO3\CMS\Core\Core\Bootstrap::getInstance()
39+
->disableCoreCache()
40+
->initializeCachingFramework()
41+
// Set all packages to active
42+
->initializePackageManagement(\TYPO3\CMS\Core\Package\UnitTestPackageManager::class);
4243

43-
if (!\TYPO3\CMS\Core\Core\Bootstrap::usesComposerClassLoading()) {
44-
// Dump autoload info if in non composer mode
45-
\TYPO3\CMS\Core\Core\ClassLoadingInformation::dumpClassLoadingInformation();
46-
\TYPO3\CMS\Core\Core\ClassLoadingInformation::registerClassLoadingInformation();
47-
}
44+
if (\TYPO3\CMS\Core\Core\Bootstrap::usesComposerClassLoading()) {
45+
return;
46+
}
47+
48+
// Dump autoload info if in non composer mode
49+
\TYPO3\CMS\Core\Core\ClassLoadingInformation::dumpClassLoadingInformation();
50+
\TYPO3\CMS\Core\Core\ClassLoadingInformation::registerClassLoadingInformation();
4851
});

0 commit comments

Comments
 (0)