- 
  Notifications
 You must be signed in to change notification settings 
- Fork 545
Handle condition with always true/false sub-condition #3313
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
|  | @@ -70,7 +70,9 @@ protected function setUp(): void | |
| $this->scope = $this->scope->assignVariable('barOrFalse', new UnionType([new ObjectType('Bar'), new ConstantBooleanType(false)]), new UnionType([new ObjectType('Bar'), new ConstantBooleanType(false)])); | ||
| $this->scope = $this->scope->assignVariable('stringOrFalse', new UnionType([new StringType(), new ConstantBooleanType(false)]), new UnionType([new StringType(), new ConstantBooleanType(false)])); | ||
| $this->scope = $this->scope->assignVariable('array', new ArrayType(new MixedType(), new MixedType()), new ArrayType(new MixedType(), new MixedType())); | ||
| $this->scope = $this->scope->assignVariable('arrayOrNull', new UnionType([new ArrayType(new MixedType(), new MixedType()), new NullType()]), new UnionType([new ArrayType(new MixedType(), new MixedType()), new NullType()])); | ||
| $this->scope = $this->scope->assignVariable('foo', new MixedType(), new MixedType()); | ||
| $this->scope = $this->scope->assignVariable('mixed', new MixedType(), new MixedType()); | ||
| $this->scope = $this->scope->assignVariable('classString', new ClassStringType(), new ClassStringType()); | ||
| $this->scope = $this->scope->assignVariable('genericClassString', new GenericClassStringType(new ObjectType('Bar')), new GenericClassStringType(new ObjectType('Bar'))); | ||
| $this->scope = $this->scope->assignVariable('object', new ObjectWithoutClassType(), new ObjectWithoutClassType()); | ||
|  | @@ -349,9 +351,17 @@ public function dataCondition(): iterable | |
| $this->createFunctionCall('is_int', 'foo'), | ||
| $this->createFunctionCall('is_string', 'bar'), | ||
| ), | ||
| [], | ||
| ['$foo' => 'int'], | ||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since  we can be sure foo is an int. I added the same test with  | ||
| ['$foo' => '~int', '$bar' => '~string'], | ||
| ], | ||
| [ | ||
| new Expr\BinaryOp\BooleanOr( | ||
| $this->createFunctionCall('is_int', 'foo'), | ||
| $this->createFunctionCall('is_string', 'mixed'), | ||
| ), | ||
| [], | ||
| ['$foo' => '~int', '$mixed' => '~string'], | ||
| ], | ||
| [ | ||
| new Expr\BinaryOp\BooleanAnd( | ||
| new Expr\BinaryOp\BooleanOr( | ||
|  | @@ -648,19 +658,37 @@ public function dataCondition(): iterable | |
| [ | ||
| new Expr\Empty_(new Variable('array')), | ||
| [ | ||
| '$array' => 'array{}|null', | ||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since  we can be sure it's an array. | ||
| '$array' => 'array{}', | ||
| ], | ||
| [ | ||
| '$array' => '~0|0.0|\'\'|\'0\'|array{}|false|null', | ||
| ], | ||
| ], | ||
| [ | ||
| new Expr\Empty_(new Variable('arrayOrNull')), | ||
| [ | ||
| '$arrayOrNull' => 'array{}|null', | ||
| ], | ||
| [ | ||
| '$arrayOrNull' => '~0|0.0|\'\'|\'0\'|array{}|false|null', | ||
| ], | ||
| ], | ||
| [ | ||
| new BooleanNot(new Expr\Empty_(new Variable('array'))), | ||
| [ | ||
| '$array' => '~0|0.0|\'\'|\'0\'|array{}|false|null', | ||
| ], | ||
| [ | ||
| '$array' => 'array{}|null', | ||
| '$array' => 'array{}', | ||
| ], | ||
| ], | ||
| [ | ||
| new BooleanNot(new Expr\Empty_(new Variable('arrayOrNull'))), | ||
| [ | ||
| '$arrayOrNull' => '~0|0.0|\'\'|\'0\'|array{}|false|null', | ||
| ], | ||
| [ | ||
| '$arrayOrNull' => 'array{}|null', | ||
| ], | ||
| ], | ||
| [ | ||
|  | ||
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| <?php declare(strict_types = 1); | ||
|  | ||
| namespace Bug11276; | ||
|  | ||
| class HelloWorld | ||
| { | ||
| /** | ||
| * @param array{from: string, to: string} $expected | ||
| */ | ||
| public function testLanguagesMatchingRegex(string $url, ?array $expected): void | ||
| { | ||
| preg_match('#\/(?<from>[a-z]{2})-(?<to>[a-z]{1}[a-z0-9]{1})\/#', $url, $matches); | ||
|  | ||
| foreach ($expected as $key => $value) { | ||
| if ($matches instanceof ArrayAccess || \array_key_exists($key, $matches)) { | ||
| $matches[$key]; | ||
| } | ||
| } | ||
|  | ||
| foreach ($expected as $key => $value) { | ||
| if (\array_key_exists($key, $matches) || $matches instanceof ArrayAccess) { | ||
| $matches[$key]; | ||
| } | ||
| } | ||
|  | ||
| foreach ($expected as $key => $value) { | ||
| if (!$matches instanceof ArrayAccess && !\array_key_exists($key, $matches)) { | ||
| } else { | ||
| $matches[$key]; | ||
| } | ||
| } | ||
|  | ||
| foreach ($expected as $key => $value) { | ||
| if (!\array_key_exists($key, $matches) && !$matches instanceof ArrayAccess) { | ||
| } else { | ||
| $matches[$key]; | ||
| } | ||
| } | ||
| } | ||
| } |