|  | 
|  | 1 | +<?xml version="1.0" encoding="UTF-8"?> | 
|  | 2 | + | 
|  | 3 | +<project name="Phing static code analysis" default="all"> | 
|  | 4 | +    <!-- Properties --> | 
|  | 5 | +    <property name="dir.base" value="." /> | 
|  | 6 | +    <property name="dir.tests" value="${project.basedir}/tests" /> | 
|  | 7 | +    <property name="dir.tests.unit" value="${project.basedir}/tests" /> | 
|  | 8 | +    <property name="dir.build" value="${project.basedir}/build" /> | 
|  | 9 | +    <property name="dir.docs" value="${dir.build}/docs" /> | 
|  | 10 | +    <property name="dir.docs.phpdoc" value="${dir.docs}/phpdoc" /> | 
|  | 11 | +    <property name="dir.reports" value="${dir.build}/logs" /> | 
|  | 12 | +    <property name="dir.reports.pdepend" value="${dir.reports}/pdepend" /> | 
|  | 13 | +    <property name="dir.reports.unit" value="${dir.reports}/phpunit" /> | 
|  | 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.unit}" /> | 
|  | 42 | +        <mkdir dir="${dir.reports.coverage}" /> | 
|  | 43 | +        <mkdir dir="${dir.reports.pdepend}" /> | 
|  | 44 | +        <mkdir dir="${dir.reports.build}" /> | 
|  | 45 | +    </target> | 
|  | 46 | + | 
|  | 47 | +    <!-- ============================================ --> | 
|  | 48 | +    <!-- Target: all (default target) --> | 
|  | 49 | +    <!-- ============================================ --> | 
|  | 50 | +    <target name="all" depends="clean, prepare"> | 
|  | 51 | +        <phingcall target="codecheck" /> | 
|  | 52 | +        <phingcall target="tests" /> | 
|  | 53 | +    	<phingcall target="documentation" /> | 
|  | 54 | +    </target> | 
|  | 55 | + | 
|  | 56 | +    <!-- ============================================ --> | 
|  | 57 | +    <!-- Target: codecheck (run all static code checks) --> | 
|  | 58 | +    <!-- ============================================ --> | 
|  | 59 | +    <target name="codecheck"> | 
|  | 60 | +        <phingcall target="lint" /> | 
|  | 61 | +        <phingcall target="codestyle" /> | 
|  | 62 | +        <phingcall target="mess" /> | 
|  | 63 | +        <phingcall target="copypaste" /> | 
|  | 64 | +    	<phingcall target="measure" /> | 
|  | 65 | +    </target> | 
|  | 66 | + | 
|  | 67 | +    <!-- ============================================ --> | 
|  | 68 | +    <!-- Target: tests (run all tests) --> | 
|  | 69 | +    <!-- ============================================ --> | 
|  | 70 | +    <target name="tests"> | 
|  | 71 | +        <!-- Now we are not running unit tests --> | 
|  | 72 | +        <!-- <phingcall target="unittests" /> --> | 
|  | 73 | +    </target> | 
|  | 74 | + | 
|  | 75 | +    <!-- ============================================ --> | 
|  | 76 | +    <!-- Target: lint (Checks code syntax) --> | 
|  | 77 | +    <!-- ============================================ --> | 
|  | 78 | +    <target name="lint"> | 
|  | 79 | +        <echo msg="Running lint to check code syntax..." /> | 
|  | 80 | +        <phplint> | 
|  | 81 | +            <fileset refid="sources" /> | 
|  | 82 | +        </phplint> | 
|  | 83 | +    </target> | 
|  | 84 | +     | 
|  | 85 | +    <!-- ============================================ --> | 
|  | 86 | +    <!-- Target: codestyle (Checks code style compliance) --> | 
|  | 87 | +    <!-- ============================================ --> | 
|  | 88 | +    <target name="codestyle"> | 
|  | 89 | +        <echo msg="Running code sniffer to check PSR2 standard..." /> | 
|  | 90 | +        <phpcodesniffer standard="PSR2" showSniffs="true" showWarnings="true" verbosity="0" encoding="UTF-8"> | 
|  | 91 | +            <fileset refid="sources" /> | 
|  | 92 | +            <formatter type="full" outfile="${dir.reports}/reportcs.txt" /> | 
|  | 93 | +            <formatter type="checkstyle" outfile="${dir.reports}/checkstylecs.xml" /> | 
|  | 94 | +        </phpcodesniffer> | 
|  | 95 | +    </target> | 
|  | 96 | + | 
|  | 97 | +    <!-- ============================================ --> | 
|  | 98 | +    <!-- Target: mess (Detects mess in code. Recommended rulesets: -->  | 
|  | 99 | +    <!-- unusedcode,codesize,controversial,design,naming) --> | 
|  | 100 | +    <!-- ============================================ --> | 
|  | 101 | +    <target name="mess"> | 
|  | 102 | +        <echo msg="Running mess detector" /> | 
|  | 103 | +        <phpmd rulesets="unusedcode,codesize,controversial,design,naming"> | 
|  | 104 | +           <fileset refid="sources" /> | 
|  | 105 | +           <formatter type="xml" outfile="${dir.reports}/pmd.xml"/> | 
|  | 106 | +        </phpmd> | 
|  | 107 | +    </target> | 
|  | 108 | + | 
|  | 109 | +    <!-- ============================================ --> | 
|  | 110 | +    <!-- Target: copypaste (detects copy/paste in code) --> | 
|  | 111 | +    <!-- ============================================ --> | 
|  | 112 | +    <target name="copypaste"> | 
|  | 113 | +        <echo msg="Running copy/paste detector..." /> | 
|  | 114 | +        <phpcpd> | 
|  | 115 | +            <fileset refid="sources" /> | 
|  | 116 | +            <formatter type="pmd" outfile="${dir.reports}/pmd-cpd.xml" /> | 
|  | 117 | +        </phpcpd> | 
|  | 118 | +    </target> | 
|  | 119 | + | 
|  | 120 | +    <!-- ============================================ --> | 
|  | 121 | +    <!-- Target: measure (measures the code) --> | 
|  | 122 | +    <!-- ============================================ --> | 
|  | 123 | +    <target name="measure"> | 
|  | 124 | +        <echo msg="Running code measurements..." /> | 
|  | 125 | +        <phploc reportType="csv" reportName="phploc" reportDirectory="${dir.reports}"> | 
|  | 126 | +            <fileset refid="sources" /> | 
|  | 127 | +        </phploc> | 
|  | 128 | +    	<phpdepend> | 
|  | 129 | +    	   <fileset refid="sources" /> | 
|  | 130 | +    	   <logger type="jdepend-xml" outfile="${dir.reports}/jdepend.xml"/> | 
|  | 131 | +    	   <analyzer type="coderank-mode" value="method"/> | 
|  | 132 | +    	 </phpdepend> | 
|  | 133 | +    </target> | 
|  | 134 | +	 | 
|  | 135 | +	<!-- ============================================ --> | 
|  | 136 | +    <!-- Target: documentation (PHP Documentor parsing) --> | 
|  | 137 | +    <!-- ============================================ --> | 
|  | 138 | +    <target name="documentation"> | 
|  | 139 | +    	<phpdoc2 title="Project Documentation" destdir="${dir.docs.phpdoc}" template="responsive-twig"> | 
|  | 140 | +    		<fileset refid="sources" /> | 
|  | 141 | +    	</phpdoc2> | 
|  | 142 | +    </target> | 
|  | 143 | +	 | 
|  | 144 | +    <!-- ============================================ --> | 
|  | 145 | +    <!-- Target: unittests (unit testing) --> | 
|  | 146 | +    <!-- ============================================ --> | 
|  | 147 | +    <target name="unittests"> | 
|  | 148 | +        <echo msg="Running unit tests..." /> | 
|  | 149 | +        <coverage-setup database="${dir.reports.unit}/coverage.db"> | 
|  | 150 | +              <fileset refid="sources" /> | 
|  | 151 | +        </coverage-setup> | 
|  | 152 | +        <phpunit configuration="${dir.tests}/phpunit.xml" codecoverage="true"> | 
|  | 153 | +            <formatter todir="${dir.reports.unit}" type="xml" /> | 
|  | 154 | +            <formatter todir="${dir.reports.unit}" type="clover" /> | 
|  | 155 | +            <batchtest> | 
|  | 156 | +                <fileset dir="${dir.tests.unit}" /> | 
|  | 157 | +            </batchtest> | 
|  | 158 | +        </phpunit> | 
|  | 159 | +        <coverage-report outfile="${dir.reports.unit}/coverage.xml"> | 
|  | 160 | +              <report todir="${dir.reports.coverage}" title="Phing unit tests run" usesorttable="true"/> | 
|  | 161 | +        </coverage-report> | 
|  | 162 | +    </target> | 
|  | 163 | +</project> | 
0 commit comments