Skip to content

Commit

Permalink
Enhancement: Enable strict_param fixer (FakerPHP#207)
Browse files Browse the repository at this point in the history
* Enhancement: Enable strict_param fixer

* Fix: Run 'make cs'

* Fix: Use non-strict comparison to retain current behaviour
  • Loading branch information
localheinz committed Dec 22, 2020
1 parent f53f67b commit a2721ba
Show file tree
Hide file tree
Showing 12 changed files with 22 additions and 21 deletions.
1 change: 1 addition & 0 deletions .php_cs.dist
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ return $config
'single_trait_insert_per_statement' => true,
'standardize_not_equals' => true,
'static_lambda' => true,
'strict_param' => true,
'switch_case_space' => true,
'ternary_operator_spaces' => true,
'ternary_to_null_coalescing' => true,
Expand Down
2 changes: 1 addition & 1 deletion src/Faker/ORM/Doctrine/EntityPopulator.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ private function generateId($obj, $column, ObjectManager $manager)

do {
$id = mt_rand();
} while (in_array($id, $ids));
} while (in_array($id, $ids, false));

return $id;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Faker/ORM/Propel/EntityPopulator.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ protected function isColumnBehavior(ColumnMap $columnMap)
case 'nested_set':
$columnNames = [$params['left_column'], $params['right_column'], $params['level_column']];

if (in_array($columnName, $columnNames)) {
if (in_array($columnName, $columnNames, false)) {
return true;
}

Expand All @@ -116,7 +116,7 @@ protected function isColumnBehavior(ColumnMap $columnMap)
case 'timestampable':
$columnNames = [$params['create_column'], $params['update_column']];

if (in_array($columnName, $columnNames)) {
if (in_array($columnName, $columnNames, false)) {
return true;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Faker/ORM/Propel2/EntityPopulator.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ protected function isColumnBehavior(ColumnMap $columnMap)
case 'nested_set':
$columnNames = [$params['left_column'], $params['right_column'], $params['level_column']];

if (in_array($columnName, $columnNames)) {
if (in_array($columnName, $columnNames, false)) {
return true;
}

Expand All @@ -118,7 +118,7 @@ protected function isColumnBehavior(ColumnMap $columnMap)
case 'timestampable':
$columnNames = [$params['create_column'], $params['update_column']];

if (in_array($columnName, $columnNames)) {
if (in_array($columnName, $columnNames, false)) {
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Faker/Provider/en_GB/Person.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public function nino(): string

do {
$prefix = implode('', self::randomElements($prefixAllowList, 2, true));
} while (in_array($prefix, $prefixBanList) || $prefix[1] == 'O');
} while (in_array($prefix, $prefixBanList, false) || $prefix[1] == 'O');

$digits = static::numerify('######');
$suffix = static::randomElement(['A', 'B', 'C', 'D']);
Expand Down
8 changes: 4 additions & 4 deletions src/Faker/Provider/en_ZA/PhoneNumber.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ public static function areaCode()

case 2:
$number = self::numberBetween(1, 8);
$digits[] = in_array($number, [5, 6]) ? $number + 2 : $number;
$digits[] = in_array($number, [5, 6], false) ? $number + 2 : $number;

break;

case 3:
$number = self::numberBetween(1, 8);
$digits[] = in_array($number, [7, 8]) ? $number - 2 : $number;
$digits[] = in_array($number, [7, 8], false) ? $number - 2 : $number;

break;

Expand All @@ -62,7 +62,7 @@ public static function areaCode()

case 5:
$number = self::numberBetween(1, 8);
$digits[] = in_array($number, [2, 5]) ? $number + 2 : $number;
$digits[] = in_array($number, [2, 5], false) ? $number + 2 : $number;

break;
}
Expand All @@ -82,7 +82,7 @@ public static function cellphoneCode()

case 7:
$number = self::numberBetween(1, 9);
$digits[] = in_array($number, [5, 7]) ? $number + 1 : $number;
$digits[] = in_array($number, [5, 7], false) ? $number + 1 : $number;

break;

Expand Down
6 changes: 3 additions & 3 deletions src/Faker/Provider/ja_JP/Text.php
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ protected static function strlen($text)

protected static function validStart($word)
{
return !in_array($word, static::$notBeginPunct);
return !in_array($word, static::$notBeginPunct, false);
}

protected static function appendEnd($text)
Expand All @@ -629,10 +629,10 @@ protected static function appendEnd($text)
$last = end($chars);
}
// if the last char is a not-valid-end punctuation, remove it
if (in_array($last, static::$notEndPunct)) {
if (in_array($last, static::$notEndPunct, false)) {
$text = preg_replace('/.$/u', '', $text);
}
// if the last char is not a valid punctuation, append a default one.
return in_array($last, static::$endPunct) ? $text : $text . '';
return in_array($last, static::$endPunct, false) ? $text : $text . '';
}
}
2 changes: 1 addition & 1 deletion src/Faker/Provider/ms_MY/Person.php
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,7 @@ public static function myKadNumber($gender = null, $hyphen = false)
$dd = DateTime::dayOfMonth();

// place of birth (1-59 except 17-20)
while (in_array($pb = self::numberBetween(1, 59), [17, 18, 19, 20])) {
while (in_array($pb = self::numberBetween(1, 59), [17, 18, 19, 20], false)) {
}

// random number
Expand Down
2 changes: 1 addition & 1 deletion src/Faker/Provider/ro_RO/Person.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public function cnp($gender = null, $dateOfBirth = null, $county = null, $isResi

if (empty($gender)) {
$gender = static::randomElement($genders);
} elseif (!in_array($gender, $genders)) {
} elseif (!in_array($gender, $genders, false)) {
throw new \InvalidArgumentException("Gender must be '{Person::GENDER_MALE}' or '{Person::GENDER_FEMALE}'");
}

Expand Down
6 changes: 3 additions & 3 deletions src/Faker/Provider/zh_TW/Text.php
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,7 @@ protected static function strlen($text)

protected static function validStart($word)
{
return !in_array($word, static::$notBeginPunct);
return !in_array($word, static::$notBeginPunct, false);
}

protected static function appendEnd($text)
Expand All @@ -842,7 +842,7 @@ protected static function appendEnd($text)
}

// if the last char is a not-valid-end punctuation, remove it
if (in_array($last, static::$notEndPunct)) {
if (in_array($last, static::$notEndPunct, false)) {
if ($mbAvailable) {
$text = mb_substr($text, 0, mb_strlen($text, static::$encoding) - 1, static::$encoding);
} else {
Expand All @@ -852,7 +852,7 @@ protected static function appendEnd($text)
}

// if the last char is not a valid punctuation, append a default one.
return in_array($last, static::$endPunct) ? $text : $text . '';
return in_array($last, static::$endPunct, false) ? $text : $text . '';
}

/**
Expand Down
2 changes: 1 addition & 1 deletion test/Faker/Provider/en_SG/PersonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function assertValidSingaporeId(string $id): void
$checksum += (int) $id[$key + 1] * $weight;
}

$checksumArr = in_array($prefix, ['F', 'G'])
$checksumArr = in_array($prefix, ['F', 'G'], true)
? ['X', 'W', 'U', 'T', 'R', 'Q', 'P', 'N', 'M', 'L', 'K']
: ['J', 'Z', 'I', 'H', 'G', 'F', 'E', 'D', 'C', 'B', 'A'];

Expand Down
4 changes: 2 additions & 2 deletions test/Faker/Provider/ro_RO/PersonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,12 +194,12 @@ public function testValidInputDataReturnsValidCnp($gender, $dateOfBirth, $county

protected function isValidFemaleCnp($value)
{
return $this->isValidCnp($value) && in_array($value[0], [2, 4, 6, 8, 9]);
return $this->isValidCnp($value) && in_array($value[0], [2, 4, 6, 8, 9], false);
}

protected function isValidMaleCnp($value)
{
return $this->isValidCnp($value) && in_array($value[0], [1, 3, 5, 7, 9]);
return $this->isValidCnp($value) && in_array($value[0], [1, 3, 5, 7, 9], false);
}

protected function isValidCnp($cnp)
Expand Down

0 comments on commit a2721ba

Please sign in to comment.