Skip to content

Commit e55a83f

Browse files
authored
Implement Type::isOffsetAccessLegal() to detect offset access that crashes even in isset()
1 parent 78d3d99 commit e55a83f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+404
-1
lines changed

src/Rules/Arrays/NonexistentOffsetInArrayDimFetchRule.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public function processNode(Node $node, Scope $scope): array
6464
return [];
6565
}
6666

67-
if ($scope->isUndefinedExpressionAllowed($node) && !$isOffsetAccessible->no()) {
67+
if ($scope->isUndefinedExpressionAllowed($node) && $isOffsetAccessibleType->isOffsetAccessLegal()->yes()) {
6868
return [];
6969
}
7070

src/Type/Accessory/AccessoryArrayListType.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,11 @@ public function isOffsetAccessible(): TrinaryLogic
142142
return TrinaryLogic::createYes();
143143
}
144144

145+
public function isOffsetAccessLegal(): TrinaryLogic
146+
{
147+
return TrinaryLogic::createYes();
148+
}
149+
145150
public function hasOffsetValueType(Type $offsetType): TrinaryLogic
146151
{
147152
return $this->getIterableKeyType()->isSuperTypeOf($offsetType)->and(TrinaryLogic::createMaybe());

src/Type/Accessory/AccessoryLiteralStringType.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,11 @@ public function isOffsetAccessible(): TrinaryLogic
132132
return TrinaryLogic::createYes();
133133
}
134134

135+
public function isOffsetAccessLegal(): TrinaryLogic
136+
{
137+
return TrinaryLogic::createYes();
138+
}
139+
135140
public function hasOffsetValueType(Type $offsetType): TrinaryLogic
136141
{
137142
return $offsetType->isInteger()->and(TrinaryLogic::createMaybe());

src/Type/Accessory/AccessoryNonEmptyStringType.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,11 @@ public function isOffsetAccessible(): TrinaryLogic
134134
return TrinaryLogic::createYes();
135135
}
136136

137+
public function isOffsetAccessLegal(): TrinaryLogic
138+
{
139+
return TrinaryLogic::createYes();
140+
}
141+
137142
public function hasOffsetValueType(Type $offsetType): TrinaryLogic
138143
{
139144
return $offsetType->isInteger()->and(TrinaryLogic::createMaybe());

src/Type/Accessory/AccessoryNonFalsyStringType.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,11 @@ public function isOffsetAccessible(): TrinaryLogic
134134
return TrinaryLogic::createYes();
135135
}
136136

137+
public function isOffsetAccessLegal(): TrinaryLogic
138+
{
139+
return TrinaryLogic::createYes();
140+
}
141+
137142
public function hasOffsetValueType(Type $offsetType): TrinaryLogic
138143
{
139144
return $offsetType->isInteger()->and(TrinaryLogic::createMaybe());

src/Type/Accessory/AccessoryNumericStringType.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,11 @@ public function isOffsetAccessible(): TrinaryLogic
137137
return TrinaryLogic::createYes();
138138
}
139139

140+
public function isOffsetAccessLegal(): TrinaryLogic
141+
{
142+
return TrinaryLogic::createYes();
143+
}
144+
140145
public function hasOffsetValueType(Type $offsetType): TrinaryLogic
141146
{
142147
return $offsetType->isInteger()->and(TrinaryLogic::createMaybe());

src/Type/Accessory/HasMethodType.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,11 @@ public function describe(VerbosityLevel $level): string
120120
return sprintf('hasMethod(%s)', $this->methodName);
121121
}
122122

123+
public function isOffsetAccessLegal(): TrinaryLogic
124+
{
125+
return TrinaryLogic::createMaybe();
126+
}
127+
123128
public function hasMethod(string $methodName): TrinaryLogic
124129
{
125130
if ($this->getCanonicalMethodName() === strtolower($methodName)) {

src/Type/Accessory/HasOffsetType.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,11 @@ public function isOffsetAccessible(): TrinaryLogic
138138
return TrinaryLogic::createYes();
139139
}
140140

141+
public function isOffsetAccessLegal(): TrinaryLogic
142+
{
143+
return TrinaryLogic::createYes();
144+
}
145+
141146
public function hasOffsetValueType(Type $offsetType): TrinaryLogic
142147
{
143148
if ($offsetType->isConstantScalarValue()->yes() && $offsetType->equals($this->offsetType)) {

src/Type/Accessory/HasOffsetValueType.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,11 @@ public function isOffsetAccessible(): TrinaryLogic
146146
return TrinaryLogic::createYes();
147147
}
148148

149+
public function isOffsetAccessLegal(): TrinaryLogic
150+
{
151+
return TrinaryLogic::createYes();
152+
}
153+
149154
public function hasOffsetValueType(Type $offsetType): TrinaryLogic
150155
{
151156
if ($offsetType->isConstantScalarValue()->yes() && $offsetType->equals($this->offsetType)) {

src/Type/Accessory/HasPropertyType.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,11 @@ public function describe(VerbosityLevel $level): string
118118
return sprintf('hasProperty(%s)', $this->propertyName);
119119
}
120120

121+
public function isOffsetAccessLegal(): TrinaryLogic
122+
{
123+
return TrinaryLogic::createMaybe();
124+
}
125+
121126
public function hasProperty(string $propertyName): TrinaryLogic
122127
{
123128
if ($this->propertyName === $propertyName) {

0 commit comments

Comments
 (0)