Skip to content

Commit 4ab5515

Browse files
committed
Refactored code. Added more tests. Added phing config. Added functionality to choose between different patterns types
1 parent db6b76b commit 4ab5515

14 files changed

+420
-140
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ vendor/
33
.buildpath
44
.project
55
.settings/
6+
build/
67

78
# Commit your application's lock file http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file
89
# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file

build.xml

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<project name="PHP-SimpleRegex" default="all">
4+
<php expression="require('vendor/autoload.php')" />
5+
6+
<!-- Properties -->
7+
<property name="dir.base" value="." />
8+
<property name="dir.tests" value="${project.basedir}/tests" />
9+
<property name="dir.build" value="${project.basedir}/build" />
10+
<property name="dir.docs" value="${dir.build}/docs" />
11+
<property name="dir.docs.phpdoc" value="${dir.docs}/phpdoc" />
12+
<property name="dir.reports" value="${dir.build}/logs" />
13+
<property name="dir.reports.pdepend" value="${dir.reports}/pdepend" />
14+
<property name="dir.reports.coverage" value="${dir.reports}/phpunit/coverage" />
15+
<property name="dir.reports.build" value="${dir.reports}/htmlreport" />
16+
17+
<!-- ============================================ -->
18+
<!-- Fileset: sources (all php files but those in test) -->
19+
<!-- ============================================ -->
20+
<fileset expandsymboliclinks="true" dir="${dir.base}" id="sources">
21+
<include name="src/**/*.php" />
22+
</fileset>
23+
24+
<!-- ============================================ -->
25+
<!-- Target: clean -->
26+
<!-- ============================================ -->
27+
<target name="clean" description="Clean up build directories.">
28+
<echo msg="Cleaning build directories ..." />
29+
<delete dir="${dir.build}" verbose="false" />
30+
</target>
31+
32+
<!-- ============================================ -->
33+
<!-- Target: prepare -->
34+
<!-- ============================================ -->
35+
<target name="prepare" description="Create build directories.">
36+
<echo msg="Creating build directories ..." />
37+
<mkdir dir="${dir.build}" />
38+
<mkdir dir="${dir.docs}" />
39+
<mkdir dir="${dir.docs.phpdoc}" />
40+
<mkdir dir="${dir.reports}" />
41+
<mkdir dir="${dir.reports.coverage}" />
42+
<mkdir dir="${dir.reports.pdepend}" />
43+
<mkdir dir="${dir.reports.build}" />
44+
</target>
45+
46+
<!-- ============================================ -->
47+
<!-- Target: all (default target) -->
48+
<!-- ============================================ -->
49+
<target name="all" depends="clean, prepare">
50+
<phingcall target="codecheck" />
51+
<phingcall target="tests" />
52+
</target>
53+
54+
<!-- ============================================ -->
55+
<!-- Target: codecheck (run all static code checks) -->
56+
<!-- ============================================ -->
57+
<target name="codecheck">
58+
<phingcall target="codestyle" />
59+
<phingcall target="mess" />
60+
<phingcall target="copypaste" />
61+
<phingcall target="measure" />
62+
<phingcall target="pdepend" />
63+
</target>
64+
65+
<!-- ============================================ -->
66+
<!-- Target: tests (run all tests) -->
67+
<!-- ============================================ -->
68+
<target name="tests">
69+
<phingcall target="unittests" />
70+
</target>
71+
72+
<!-- ============================================ -->
73+
<!-- Target: codestyle (Checks code style compliance) -->
74+
<!-- ============================================ -->
75+
<target name="codestyle">
76+
<echo msg="Running code sniffer to check zend standard..." />
77+
<phpcodesniffer standard="PSR2" showSniffs="true" showWarnings="true" verbosity="0" encoding="UTF-8">
78+
<fileset refid="sources" />
79+
<formatter type="full" outfile="${dir.reports}/reportcs.txt" />
80+
<formatter type="checkstyle" outfile="${dir.reports}/checkstylecs.xml" />
81+
</phpcodesniffer>
82+
</target>
83+
84+
<!-- ============================================ -->
85+
<!-- Target: mess (Detects mess in code. Recommended rulesets: -->
86+
<!-- unusedcode,codesize,controversial,design,naming) -->
87+
<!-- ============================================ -->
88+
<target name="mess">
89+
<echo msg="Running mess detector" />
90+
<phpmd rulesets="unusedcode,codesize,controversial,design,naming">
91+
<fileset refid="sources" />
92+
<formatter type="xml" outfile="${dir.reports}/pmd.xml"/>
93+
</phpmd>
94+
</target>
95+
96+
<target name="pdepend">
97+
<echo msg="Running phpdepend analysis..." />
98+
<phpdepend>
99+
<fileset refid="sources" />
100+
<analyzer type="coderank-mode" value="method" />
101+
<logger type="jdepend-xml" outfile="${dir.reports}/pdepend/pdepend.xml" />
102+
<logger type="jdepend-chart" outfile="${dir.reports}/pdepend/dependencies.svg"/>
103+
<logger type="overview-pyramid" outfile="${dir.reports}/pdepend/overview-pyramid.svg"/>
104+
</phpdepend>
105+
</target>
106+
107+
<!-- ============================================ -->
108+
<!-- Target: copypaste (detects copy/paste in code) -->
109+
<!-- ============================================ -->
110+
<target name="copypaste">
111+
<echo msg="Running copy/paste detector..." />
112+
<phpcpd>
113+
<fileset refid="sources" />
114+
<formatter type="pmd" outfile="${dir.reports}/pmd-cpd.xml" />
115+
</phpcpd>
116+
</target>
117+
118+
<!-- ============================================ -->
119+
<!-- Target: measure (measures the code) -->
120+
<!-- ============================================ -->
121+
<target name="measure">
122+
<echo msg="Running code measurements..." />
123+
<phploc reportType="csv" reportName="phploc" reportDirectory="${dir.reports}">
124+
<fileset refid="sources" />
125+
</phploc>
126+
</target>
127+
128+
<!-- ============================================ -->
129+
<!-- Target: unittests (unit testing) -->
130+
<!-- ============================================ -->
131+
<target name="unittests">
132+
<echo msg="Running unit tests..." />
133+
<phpunit>
134+
<formatter type="clover" toDir="build/reports/coverage" />
135+
<formatter type="xml" outfile="build/reports/phpunit.xml" />
136+
<formatter type="summary" outfile="build/reports/phpunit.xml" />
137+
<batchtest>
138+
<fileset dir="${dir.tests}" />
139+
</batchtest>
140+
</phpunit>
141+
<exec command="./vendor/bin/phpunit -d zend.enable_gc=0 --log-junit ${dir.reports}/phpunit/phpunit.xml --coverage-clover ${dir.reports.coverage}/clover.xml --coverage-html ${dir.reports.coverage}/ --testdox-html ${dir.reports}/phpunit/testdox.html -c ${dir.tests}" outputProperty="output" returnProperty="returnout" />
142+
<echo msg="${output}" />
143+
<if>
144+
<not>
145+
<equals arg1="${returnout}" arg2="0" />
146+
</not>
147+
<then>
148+
<fail msg="Failures occurred in unit tests." />
149+
</then>
150+
</if>
151+
</target>
152+
</project>

composer.json

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@
1010
"Mcustiel\\PhpSimpleRegex\\" : "src"
1111
}
1212
},
13-
"autoload-dev": {
14-
"psr-4": { "Test\\Mcustiel\\PhpSimpleRegex\\": "tests/unit" }
15-
}
13+
"autoload-dev" : {
14+
"psr-4" : {
15+
"Test\\Mcustiel\\PhpSimpleRegex\\" : "tests/unit"
16+
}
17+
},
1618
"name" : "mcustiel/php-simple-regex",
1719
"type" : "library",
1820
"description" : "This is a library with a set of utils to execute and get the response from regular expressions",
@@ -21,11 +23,13 @@
2123
"php" : ">=5.5"
2224
},
2325
"require-dev" : {
24-
"phpunit/phpunit" : ">=4.7.7",
25-
"phing/phing" : ">=2.11.0",
26-
"squizlabs/php_codesniffer" : ">=2.3.3",
27-
"phpmd/phpmd" : ">=2.2.3",
28-
"sebastian/phpcpd" : ">=2.0.2",
29-
"verbalexpressions/php-verbal-expressions" : "dev-master"
30-
}
26+
"phpunit/phpunit" : ">=4.7.7",
27+
"phing/phing" : ">=2.11.0",
28+
"squizlabs/php_codesniffer" : ">=2.3.3",
29+
"phpmd/phpmd" : ">=2.2.3",
30+
"sebastian/phpcpd" : ">=2.0.2",
31+
"phploc/phploc" : ">=2.1.3",
32+
"verbalexpressions/php-verbal-expressions" : "dev-master",
33+
"selvinortiz/flux" : "dev-master"
34+
}
3135
}

src/AbstractMatch.php

Lines changed: 0 additions & 29 deletions
This file was deleted.

0 commit comments

Comments
 (0)