Skip to content

Commit

Permalink
Bug #3, PHP script to modify phpcs.xml [iet:3791672]
Browse files Browse the repository at this point in the history
* Dynamically modify PHP_CodeSniffer configuration XML
  • Loading branch information
nfreear committed Jul 23, 2015
1 parent 0b52b71 commit 7e99798
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 3 deletions.
29 changes: 29 additions & 0 deletions bin/dyn-phpcs-xml.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env php
<?php
/**
* Dynamically modify 'phpcs.xml' CodeSniffer configurations, based on conditional comments.
*
* Usage: dyn-phpcs-xml --no-ns vendor/iet-ou/open-media-player-core/phpcs.xml > phpcs-1.xml
*
* @copyright Copyright 2015 The Open University.
* @author N.D.Freear, 22 July 2015.
*/

fprintf(STDERR, "dyn-php-xml\n");

if ($argc < 3) {
fprintf(STDERR, "Error, insufficient arguments.\n");
exit(1);
}

$filename = $argv[ $argc - 1 ];

$xml = file_get_contents($filename);

$xml = preg_replace('@<!--\[if DYN:NO-NS\]>(?P<dyn>[^\[]+)<!\[endif\]-->@msi', '$1', $xml);
//$xml = preg_replace('@<!--\{DYN:NO-NS\}(?P<dyn>[^\{]+)\{\/DYN:NO-NS\}-->@i', '$1', $xml);

echo $xml;


//End.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"scripts": {
"test": [
"composer validate #--no-interaction",
"parallel-lint src/*",
"#parallel-lint src/*",
"phpcs --standard=./phpcs.xml -n --encoding=utf-8 --extensions=php src/*",
"phpunit"
],
Expand All @@ -53,6 +53,7 @@
"phpcbf --standard=./phpcs.xml -n -l --encoding=utf-8 --extensions=php tests/*"
]
},
"bin": [ "./bin/dyn-phpcs-xml.php" ],
"config": {
"preferred-install": "dist"
},
Expand Down
12 changes: 10 additions & 2 deletions phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
<!-- Temporarily exclude all views and provider-libraries. -->
<exclude-pattern>/views/</exclude-pattern>
<exclude-pattern>src/providers/</exclude-pattern>
<exclude-pattern>/application/models/</exclude-pattern>
<exclude-pattern>/libraries/MY_User_agent.php</exclude-pattern>
<exclude-pattern>/controllers/xml_namespace.php</exclude-pattern>


<rule ref="PSR2">
Expand All @@ -39,7 +42,9 @@
<!--
For the moment, don't require namespaces.
-->
<!--<exclude name="PSR1.Classes.ClassDeclaration"/>-->
<!--[if DYN:NO-NS]>
<exclude name="PSR1.Classes.ClassDeclaration"/>
<![endif]-->

<!--<exclude name="PSR1.Files.SideEffects"/>-->
</rule>
Expand All @@ -53,7 +58,10 @@
<exclude-pattern>/application/controllers/</exclude-pattern>

<exclude name="Squiz.Classes.ValidClassName"/>
<!--<exclude name="Squiz.Classes.ClassFileName"/>-->

<!--[if DYN:CFN]>
<exclude name="Squiz.Classes.ClassFileName"/>
<![endif]-->
</rule>

<!--
Expand Down

0 comments on commit 7e99798

Please sign in to comment.