Skip to content

Commit 0ce7141

Browse files
committed
Added support for setting PHP ini values in ruleset.xml files (request #560)
1 parent ab7e490 commit 0ce7141

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

CodeSniffer.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -789,6 +789,34 @@ public function processRuleset($rulesetPath, $depth=0)
789789
}
790790
}//end foreach
791791

792+
// Set custom php ini values as CLI args.
793+
foreach ($ruleset->{'ini'} as $arg) {
794+
if ($this->_shouldProcessElement($arg) === false) {
795+
continue;
796+
}
797+
798+
if (isset($arg['name']) === false) {
799+
continue;
800+
}
801+
802+
$name = (string) $arg['name'];
803+
$argString = $name;
804+
if (isset($arg['value']) === true) {
805+
$value = (string) $arg['value'];
806+
$argString .= "=$value";
807+
} else {
808+
$value = 'true';
809+
}
810+
811+
$cliArgs[] = '-d';
812+
$cliArgs[] = $argString;
813+
814+
if (PHP_CODESNIFFER_VERBOSITY > 1) {
815+
echo str_repeat("\t", $depth);
816+
echo "\t=> set PHP ini value $name to $value".PHP_EOL;
817+
}
818+
}//end foreach
819+
792820
if (empty($cliValues['files']) === true
793821
&& $rulesetDir === getcwd()
794822
) {

package.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ http://pear.php.net/dtd/package-2.0.xsd">
3131
-- This file is still only used if no standard is specified on the command line
3232
- Added support for a phpcs.xml.dist file (request #583)
3333
-- If both a phpcs.xml and phpcs.xml.dist file are present, the phpcs.xml file will be used
34+
- Added support for setting PHP ini values in ruleset.xml files (request #560)
35+
-- Setting the value of the new ini tags to name="memory_limit" value="32M" is the same as -d memory_limit=32M
3436
- Added support for one or more bootstrap files to be run before processing begins
3537
-- Use the --bootstrap=file,file,file command line argument to include bootstrap files
3638
-- Ueeful if you want to override some of the high-level settings of PHPCS or PHPCBF

phpcs.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,7 @@
1111
<arg name="report" value="summary"/>
1212
<arg value="np"/>
1313

14+
<ini name="memory_limit" value="64M"/>
15+
1416
<rule ref="PHPCS"/>
15-
</ruleset>
17+
</ruleset>

0 commit comments

Comments
 (0)