Skip to content

Commit 4d1be15

Browse files
Refactor build system.
1 parent e3e2273 commit 4d1be15

File tree

6 files changed

+271
-3
lines changed

6 files changed

+271
-3
lines changed

.gitignore

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
build/api
2+
build/code-browser
3+
build/coverage
4+
build/logs
5+
build/pdepend
6+
cache.properties
7+
phpunit.xml

build.xml

+158-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,162 @@
1-
<project name="php-file-iterator" default="phpab" basedir=".">
2-
<target name="phpab">
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<project name="File_Iterator" default="build">
4+
<property name="php" value="php"/>
5+
<property name="phpunit" value="phpunit"/>
6+
7+
<target name="build"
8+
depends="prepare,lint,phploc,pdepend,phpmd-ci,phpcs-ci,phpcpd,phpcb"/>
9+
10+
<target name="build-parallel"
11+
depends="prepare,lint,tools-parallel,phpcb"/>
12+
13+
<target name="tools-parallel"
14+
description="Run tools in parallel">
15+
<parallel threadCount="2">
16+
<sequential>
17+
<antcall target="pdepend"/>
18+
<antcall target="phpmd-ci"/>
19+
</sequential>
20+
<antcall target="phpcpd"/>
21+
<antcall target="phpcs-ci"/>
22+
<antcall target="phploc"/>
23+
</parallel>
24+
</target>
25+
26+
<target name="clean" description="Cleanup build artifacts">
27+
<delete dir="${basedir}/build/api"/>
28+
<delete dir="${basedir}/build/code-browser"/>
29+
<delete dir="${basedir}/build/coverage"/>
30+
<delete dir="${basedir}/build/logs"/>
31+
<delete dir="${basedir}/build/pdepend"/>
32+
</target>
33+
34+
<target name="prepare" depends="clean,phpab"
35+
description="Prepare for build">
36+
<mkdir dir="${basedir}/build/api"/>
37+
<mkdir dir="${basedir}/build/code-browser"/>
38+
<mkdir dir="${basedir}/build/coverage"/>
39+
<mkdir dir="${basedir}/build/logs"/>
40+
<mkdir dir="${basedir}/build/pdepend"/>
41+
</target>
42+
43+
<target name="phpab" description="Generate autoloader scripts">
344
<exec executable="phpab">
4-
<arg line='-o File/Iterator/Autoload.php -c -t File/Iterator/Autoload.php.in --indent " " File' />
45+
<arg value="--output" />
46+
<arg path="File/Iterator/Autoload.php" />
47+
<arg value="--compat" />
48+
<arg value="--template" />
49+
<arg path="File/Iterator/Autoload.php.in" />
50+
<arg value="--indent" />
51+
<arg value=" " />
52+
<arg path="File" />
53+
</exec>
54+
</target>
55+
56+
<target name="lint">
57+
<apply executable="${php}" failonerror="true">
58+
<arg value="-l" />
59+
60+
<fileset dir="${basedir}/File">
61+
<include name="**/*.php" />
62+
<modified />
63+
</fileset>
64+
<!--
65+
<fileset dir="${basedir}/Tests">
66+
<include name="**/*.php" />
67+
<modified />
68+
</fileset>
69+
-->
70+
</apply>
71+
</target>
72+
73+
<target name="phploc" description="Measure project size using PHPLOC">
74+
<exec executable="phploc">
75+
<arg value="--log-csv" />
76+
<arg value="${basedir}/build/logs/phploc.csv" />
77+
<arg path="${basedir}/File" />
78+
</exec>
79+
</target>
80+
81+
<target name="pdepend"
82+
description="Calculate software metrics using PHP_Depend">
83+
<exec executable="pdepend">
84+
<arg value="--jdepend-xml=${basedir}/build/logs/jdepend.xml" />
85+
<arg value="--jdepend-chart=${basedir}/build/pdepend/dependencies.svg" />
86+
<arg value="--overview-pyramid=${basedir}/build/pdepend/overview-pyramid.svg" />
87+
<arg path="${basedir}/File" />
88+
</exec>
89+
</target>
90+
91+
<target name="phpmd"
92+
description="Perform project mess detection using PHPMD">
93+
<exec executable="phpmd">
94+
<arg path="${basedir}/File" />
95+
<arg value="text" />
96+
<arg value="${basedir}/build/phpmd.xml" />
97+
</exec>
98+
</target>
99+
100+
<target name="phpmd-ci"
101+
description="Perform project mess detection using PHPMD">
102+
<exec executable="phpmd">
103+
<arg path="${basedir}/File" />
104+
<arg value="xml" />
105+
<arg value="${basedir}/build/phpmd.xml" />
106+
<arg value="--reportfile" />
107+
<arg value="${basedir}/build/logs/pmd.xml" />
108+
</exec>
109+
</target>
110+
111+
<target name="phpcs"
112+
description="Find coding standard violations using PHP_CodeSniffer">
113+
<exec executable="phpcs">
114+
<arg value="--standard=${basedir}/build/PHPCS" />
115+
<arg value="--extensions=php" />
116+
<arg value="--ignore=Autoload.php" />
117+
<arg path="${basedir}/File" />
118+
</exec>
119+
</target>
120+
121+
<target name="phpcs-ci"
122+
description="Find coding standard violations using PHP_CodeSniffer">
123+
<exec executable="phpcs" output="/dev/null">
124+
<arg value="--report=checkstyle" />
125+
<arg value="--report-file=${basedir}/build/logs/checkstyle.xml" />
126+
<arg value="--standard=${basedir}/build/PHPCS" />
127+
<arg value="--extensions=php" />
128+
<arg value="--ignore=Autoload.php" />
129+
<arg path="${basedir}/File" />
130+
</exec>
131+
</target>
132+
133+
<target name="phpcpd" description="Find duplicate code using PHPCPD">
134+
<exec executable="phpcpd">
135+
<arg value="--log-pmd" />
136+
<arg value="${basedir}/build/logs/pmd-cpd.xml" />
137+
<arg path="${basedir}/File" />
138+
</exec>
139+
</target>
140+
141+
<target name="phpunit" description="Run unit tests with PHPUnit">
142+
<condition property="phpunit_cmd" value="${php} ${phpunit}" else="${phpunit}">
143+
<not>
144+
<equals arg1="${phpunit}" arg2="phpunit" />
145+
</not>
146+
</condition>
147+
148+
<exec executable="${phpunit_cmd}" failonerror="true"/>
149+
</target>
150+
151+
<target name="phpcb"
152+
description="Aggregate tool output with PHP_CodeBrowser">
153+
<exec executable="phpcb">
154+
<arg value="--log" />
155+
<arg path="${basedir}/build/logs" />
156+
<arg value="--source" />
157+
<arg path="${basedir}/File" />
158+
<arg value="--output" />
159+
<arg path="${basedir}/build/code-browser" />
5160
</exec>
6161
</target>
7162
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
class PHPCS_Sniffs_ControlStructures_ControlSignatureSniff extends PHP_CodeSniffer_Standards_AbstractPatternSniff
3+
{
4+
public function __construct()
5+
{
6+
parent::__construct(true);
7+
}
8+
9+
protected function getPatterns()
10+
{
11+
return array(
12+
'do {EOL...} while (...);EOL',
13+
'while (...) {EOL',
14+
'for (...) {EOL',
15+
'if (...) {EOL',
16+
'foreach (...) {EOL',
17+
'}EOLelse if (...) {EOL',
18+
'}EOLelse {EOL',
19+
'do {EOL',
20+
);
21+
}
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
class PHPCS_Sniffs_Whitespace_ConcatenationSpacingSniff implements PHP_CodeSniffer_Sniff
3+
{
4+
public function register()
5+
{
6+
return array(T_STRING_CONCAT);
7+
}
8+
9+
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
10+
{
11+
$tokens = $phpcsFile->getTokens();
12+
13+
if ($tokens[($stackPtr - 1)]['code'] !== T_WHITESPACE ||
14+
$tokens[($stackPtr + 1)]['code'] !== T_WHITESPACE) {
15+
16+
$phpcsFile->addError(
17+
'Concatenation operator must be surrounded by whitespace',
18+
$stackPtr
19+
);
20+
}
21+
}
22+
}

build/PHPCS/ruleset.xml

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?xml version="1.0"?>
2+
<ruleset name="Sebastian">
3+
<description>Sebastian Bergmann's coding standard</description>
4+
5+
<rule ref="Generic.CodeAnalysis.ForLoopShouldBeWhileLoop"/>
6+
<rule ref="Generic.CodeAnalysis.ForLoopWithTestFunctionCall"/>
7+
<rule ref="Generic.CodeAnalysis.JumbledIncrementer"/>
8+
<rule ref="Generic.CodeAnalysis.UnconditionalIfStatement"/>
9+
<rule ref="Generic.CodeAnalysis.UnnecessaryFinalModifier"/>
10+
<rule ref="Generic.CodeAnalysis.UselessOverridingMethod"/>
11+
12+
<rule ref="Generic.Commenting.Todo"/>
13+
14+
<rule ref="Generic.ControlStructures.InlineControlStructure"/>
15+
16+
<rule ref="Generic.Files.LineEndings"/>
17+
18+
<rule ref="Generic.Formatting.DisallowMultipleStatements"/>
19+
<rule ref="Generic.Formatting.NoSpaceAfterCast"/>
20+
21+
<rule ref="Generic.Functions.OpeningFunctionBraceBsdAllman"/>
22+
<rule ref="PEAR.Functions.ValidDefaultValue"/>
23+
24+
<rule ref="Generic.NamingConventions.ConstructorName"/>
25+
<rule ref="Generic.NamingConventions.UpperCaseConstantName"/>
26+
<rule ref="PEAR.NamingConventions.ValidClassName"/>
27+
28+
<rule ref="Generic.PHP.DisallowShortOpenTag"/>
29+
<rule ref="Generic.PHP.NoSilencedErrors"/>
30+
<rule ref="Generic.PHP.UpperCaseConstant"/>
31+
32+
<rule ref="Generic.WhiteSpace.DisallowTabIndent"/>
33+
<rule ref="Generic.WhiteSpace.ScopeIndent"/>
34+
<rule ref="Squiz.WhiteSpace.SuperfluousWhitespace"/>
35+
</ruleset>

build/phpmd.xml

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0"?>
2+
3+
<ruleset name="Sebastian"
4+
xmlns="http://pmd.sf.net/ruleset/1.0.0"
5+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
6+
xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd"
7+
xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd">
8+
<description>Sebastian Bergmann's ruleset</description>
9+
10+
<rule ref="rulesets/codesize.xml/CyclomaticComplexity" />
11+
<rule ref="rulesets/codesize.xml/NPathComplexity" />
12+
<rule ref="rulesets/codesize.xml/ExcessiveClassComplexity" />
13+
<rule ref="rulesets/codesize.xml/ExcessiveClassLength" />
14+
<rule ref="rulesets/codesize.xml/ExcessiveMethodLength" />
15+
<rule ref="rulesets/codesize.xml/ExcessiveParameterList" />
16+
17+
<rule ref="rulesets/design.xml/EvalExpression" />
18+
<rule ref="rulesets/design.xml/ExitExpression" />
19+
<rule ref="rulesets/design.xml/GotoStatement" />
20+
21+
<rule ref="rulesets/naming.xml/ConstructorWithNameAsEnclosingClass" />
22+
23+
<rule ref="rulesets/unusedcode.xml/UnusedFormalParameter" />
24+
<rule ref="rulesets/unusedcode.xml/UnusedLocalVariable" />
25+
<rule ref="rulesets/unusedcode.xml/UnusedPrivateField" />
26+
<rule ref="rulesets/unusedcode.xml/UnusedPrivateMethod" />
27+
</ruleset>

0 commit comments

Comments
 (0)