Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions src/Ruleset.php
Original file line number Diff line number Diff line change
Expand Up @@ -1646,23 +1646,27 @@ public function setSniffProperty($sniffClass, $name, $settings)
return;
}

$value = $this->getRealPropertyValue($settings['value']);
$value = $settings['value'];

// Handle properties set inline via phpcs:set.
if (substr($name, -2) === '[]') {
$values = [];
if (is_string($value) === true) {
foreach (explode(',', $value) as $val) {
list($k, $v) = explode('=>', $val.'=>');
if ($v !== '') {
$values[trim($k)] = $v;
} else {
$values[] = $k;
if (trim($value) !== '') {
foreach (explode(',', $value) as $val) {
list($k, $v) = explode('=>', $val.'=>');
if ($v !== '') {
$values[trim($k)] = $v;
} else {
$values[] = $k;
}
}
}
}

$value = $this->getRealPropertyValue($values);
} else {
$value = $this->getRealPropertyValue($value);
}

if (isset($settings['extend']) === true
Expand Down
4 changes: 4 additions & 0 deletions tests/Core/Ruleset/Fixtures/PropertyTypeHandlingInline.inc
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,8 @@
// phpcs:set TestStandard.SetProperty.PropertyTypeHandling expectsArrayWithKeysAndValues[] string=>string,10=>10,float=>1.5,null=>null,true=>true,false=>false
// phpcs:set TestStandard.SetProperty.PropertyTypeHandling expectsEmptyArray[]

// phpcs:set TestStandard.SetProperty.PropertyTypeHandling expectsArrayWithJustValueTrue[] true
// phpcs:set TestStandard.SetProperty.PropertyTypeHandling expectsArrayWithJustValueFalse[] false
// phpcs:set TestStandard.SetProperty.PropertyTypeHandling expectsArrayWithJustValueNull[] null

echo 'hello!';
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,27 @@ final class PropertyTypeHandlingSniff implements Sniff
'predefinedB' => ' null ',
];

/**
* Used to verify that - in particular inline - array properties with only a "special" value get handled correctly.
*
* @var array<mixed>
*/
public $expectsArrayWithJustValueTrue = [];

/**
* Used to verify that - in particular inline - array properties with only a "special" value get handled correctly.
*
* @var array<mixed>
*/
public $expectsArrayWithJustValueFalse = [];

/**
* Used to verify that - in particular inline - array properties with only a "special" value get handled correctly.
*
* @var array<mixed>
*/
public $expectsArrayWithJustValueNull = [];

/**
* Used to verify that if `extend` is used on a non-array property, the value still gets set, but not as an array.
*
Expand Down
12 changes: 12 additions & 0 deletions tests/Core/Ruleset/PropertyTypeHandlingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,18 @@ public static function dataTypeHandling()
'propertyName' => 'expectsEmptyArray',
'expected' => [],
],
'Array with just the value "true"' => [
'propertyName' => 'expectsArrayWithJustValueTrue',
'expected' => [true],
],
'Array with just the value "false"' => [
'propertyName' => 'expectsArrayWithJustValueFalse',
'expected' => [false],
],
'Array with just the value "null"' => [
'propertyName' => 'expectsArrayWithJustValueNull',
'expected' => [null],
],
];

}//end dataTypeHandling()
Expand Down
12 changes: 12 additions & 0 deletions tests/Core/Ruleset/PropertyTypeHandlingTest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,18 @@
<element value="true"/>
</property>

<property name="expectsArrayWithJustValueTrue" type="array">
<element value="true"/>
</property>

<property name="expectsArrayWithJustValueFalse" type="array">
<element value="false"/>
</property>

<property name="expectsArrayWithJustValueNull" type="array">
<element value="null"/>
</property>

<property name="expectsStringNotArray" extend="true" value="some value"/>

</properties>
Expand Down
Loading