Skip to content

Commit aa068f9

Browse files
Replace in_array() by isset()
1 parent e917b00 commit aa068f9

File tree

3 files changed

+29
-20
lines changed

3 files changed

+29
-20
lines changed

app/code/Magento/Catalog/Model/ResourceModel/Eav/Attribute.php

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,18 @@ class Attribute extends \Magento\Eav\Model\Entity\Attribute implements
3838

3939
const KEY_IS_GLOBAL = 'is_global';
4040

41+
private const ALLOWED_INPUT_TYPES = [
42+
'boolean' => true,
43+
'date' => true,
44+
'datetime' => true,
45+
'multiselect' => true,
46+
'price' => true,
47+
'select' => true,
48+
'text' => true,
49+
'textarea' => true,
50+
'weight' => true,
51+
];
52+
4153
/**
4254
* @var LockValidatorInterface
4355
*/
@@ -403,18 +415,7 @@ public function getSourceModel()
403415
*/
404416
public function isAllowedForRuleCondition()
405417
{
406-
$allowedInputTypes = [
407-
'boolean',
408-
'date',
409-
'datetime',
410-
'multiselect',
411-
'price',
412-
'select',
413-
'text',
414-
'textarea',
415-
'weight',
416-
];
417-
return $this->getIsVisible() && in_array($this->getFrontendInput(), $allowedInputTypes);
418+
return $this->getIsVisible() && isset(self::ALLOWED_INPUT_TYPES[$this->getFrontendInput()]);
418419
}
419420

420421
/**

lib/internal/Magento/Framework/DB/Select/SelectRenderer.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212
*/
1313
class SelectRenderer implements RendererInterface
1414
{
15+
private const MANDATORY_SELECT_PARTS = [
16+
Select::COLUMNS => true,
17+
Select::FROM => true
18+
];
19+
1520
/**
1621
* @var RendererInterface[]
1722
*/
@@ -67,7 +72,8 @@ public function render(Select $select, $sql = '')
6772
{
6873
$sql = Select::SQL_SELECT;
6974
foreach ($this->renderers as $renderer) {
70-
if (in_array($renderer['part'], [Select::COLUMNS, Select::FROM]) || $select->getPart($renderer['part'])) {
75+
$part = $renderer['part'];
76+
if (isset(self::MANDATORY_SELECT_PARTS[$part]) || $select->getPart($part)) {
7177
$sql = $renderer['renderer']->render($select, $sql);
7278
}
7379
}

lib/internal/Magento/Framework/Module/Dir.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@ class Dir
2222
const MODULE_SETUP_DIR = 'Setup';
2323
/**#@-*/
2424

25+
private const ALLOWED_DIR_TYPES = [
26+
self::MODULE_ETC_DIR => true,
27+
self::MODULE_I18N_DIR => true,
28+
self::MODULE_VIEW_DIR => true,
29+
self::MODULE_CONTROLLER_DIR => true,
30+
self::MODULE_SETUP_DIR => true
31+
];
32+
2533
/**#@-*/
2634
private $componentRegistrar;
2735

@@ -52,13 +60,7 @@ public function getDir($moduleName, $type = '')
5260
}
5361

5462
if ($type) {
55-
if (!in_array($type, [
56-
self::MODULE_ETC_DIR,
57-
self::MODULE_I18N_DIR,
58-
self::MODULE_VIEW_DIR,
59-
self::MODULE_CONTROLLER_DIR,
60-
self::MODULE_SETUP_DIR
61-
])) {
63+
if (!isset(self::ALLOWED_DIR_TYPES[$type])) {
6264
throw new \InvalidArgumentException("Directory type '{$type}' is not recognized.");
6365
}
6466
$path .= '/' . $type;

0 commit comments

Comments
 (0)