Skip to content

Commit 7241e59

Browse files
committed
TASK: Simplify code to use null-safe operator ?? consistently
1 parent 568381b commit 7241e59

File tree

1 file changed

+14
-29
lines changed

1 file changed

+14
-29
lines changed

Neos.Flow/Classes/Reflection/ReflectionService.php

Lines changed: 14 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ public function getDefaultImplementationClassNameForInterface(string $interfaceN
284284
}
285285
$interfaceName = $this->prepareClassReflectionForUsage($interfaceName);
286286

287-
$classNamesFound = isset($this->classReflectionData[$interfaceName][self::DATA_INTERFACE_IMPLEMENTATIONS]) ? array_keys($this->classReflectionData[$interfaceName][self::DATA_INTERFACE_IMPLEMENTATIONS]) : [];
287+
$classNamesFound = array_keys($this->classReflectionData[$interfaceName][self::DATA_INTERFACE_IMPLEMENTATIONS] ?? []);
288288
if (count($classNamesFound) === 1) {
289289
return $classNamesFound[0];
290290
}
@@ -320,7 +320,7 @@ public function getAllImplementationClassNamesForInterface(string $interfaceName
320320
}
321321
$interfaceName = $this->prepareClassReflectionForUsage($interfaceName);
322322

323-
return (isset($this->classReflectionData[$interfaceName][self::DATA_INTERFACE_IMPLEMENTATIONS])) ? array_keys($this->classReflectionData[$interfaceName][self::DATA_INTERFACE_IMPLEMENTATIONS]) : [];
323+
return array_keys($this->classReflectionData[$interfaceName][self::DATA_INTERFACE_IMPLEMENTATIONS] ?? []);
324324
}
325325

326326
/**
@@ -340,7 +340,7 @@ public function getAllSubClassNamesForClass(string $className): array
340340
throw new \InvalidArgumentException('"' . $className . '" does not exist or is not the name of a class.', 1257168042);
341341
}
342342
$className = $this->prepareClassReflectionForUsage($className);
343-
return (isset($this->classReflectionData[$className][self::DATA_CLASS_SUBCLASSES])) ? array_keys($this->classReflectionData[$className][self::DATA_CLASS_SUBCLASSES]) : [];
343+
return array_keys($this->classReflectionData[$className][self::DATA_CLASS_SUBCLASSES] ?? []);
344344
}
345345

346346
/**
@@ -354,7 +354,7 @@ public function getClassNamesByAnnotation(string $annotationClassName): array
354354
}
355355
$annotationClassName = $this->cleanClassName($annotationClassName);
356356

357-
return (isset($this->annotatedClasses[$annotationClassName]) ? array_keys($this->annotatedClasses[$annotationClassName]) : []);
357+
return array_keys($this->annotatedClasses[$annotationClassName] ?? []);
358358
}
359359

360360
/**
@@ -371,7 +371,7 @@ public function isClassAnnotatedWith(string $className, string $annotationClassN
371371

372372
$annotationClassName = $this->cleanClassName($annotationClassName);
373373

374-
return (isset($this->annotatedClasses[$annotationClassName][$className]));
374+
return isset($this->annotatedClasses[$annotationClassName][$className]);
375375
}
376376

377377
/**
@@ -442,7 +442,7 @@ public function isClassImplementationOf(string $className, string $interfaceName
442442
$className = $this->prepareClassReflectionForUsage($className);
443443
$this->prepareClassReflectionForUsage($interfaceName);
444444

445-
return (isset($this->classReflectionData[$interfaceName][self::DATA_INTERFACE_IMPLEMENTATIONS][$className]));
445+
return isset($this->classReflectionData[$interfaceName][self::DATA_INTERFACE_IMPLEMENTATIONS][$className]);
446446
}
447447

448448
/**
@@ -515,7 +515,7 @@ public function getClassesContainingMethodsAnnotatedWith(string $annotationClass
515515
$this->initialize();
516516
}
517517

518-
return isset($this->classesByMethodAnnotations[$annotationClassName]) ? array_keys($this->classesByMethodAnnotations[$annotationClassName]) : [];
518+
return array_keys($this->classesByMethodAnnotations[$annotationClassName] ?? []);
519519
}
520520

521521
/**
@@ -573,7 +573,7 @@ public function isMethodStatic(string $className, string $methodName): bool
573573
public function isMethodPublic(string $className, string $methodName): bool
574574
{
575575
$className = $this->prepareClassReflectionForUsage($className);
576-
return (isset($this->classReflectionData[$className][self::DATA_CLASS_METHODS][$methodName][self::DATA_METHOD_VISIBILITY]) && $this->classReflectionData[$className][self::DATA_CLASS_METHODS][$methodName][self::DATA_METHOD_VISIBILITY] === self::VISIBILITY_PUBLIC);
576+
return ($this->classReflectionData[$className][self::DATA_CLASS_METHODS][$methodName][self::DATA_METHOD_VISIBILITY] ?? null) === self::VISIBILITY_PUBLIC;
577577
}
578578

579579
/**
@@ -586,7 +586,7 @@ public function isMethodPublic(string $className, string $methodName): bool
586586
public function isMethodProtected(string $className, string $methodName): bool
587587
{
588588
$className = $this->prepareClassReflectionForUsage($className);
589-
return (isset($this->classReflectionData[$className][self::DATA_CLASS_METHODS][$methodName][self::DATA_METHOD_VISIBILITY]) && $this->classReflectionData[$className][self::DATA_CLASS_METHODS][$methodName][self::DATA_METHOD_VISIBILITY] === self::VISIBILITY_PROTECTED);
589+
return ($this->classReflectionData[$className][self::DATA_CLASS_METHODS][$methodName][self::DATA_METHOD_VISIBILITY] ?? null) === self::VISIBILITY_PROTECTED;
590590
}
591591

592592
/**
@@ -599,7 +599,7 @@ public function isMethodProtected(string $className, string $methodName): bool
599599
public function isMethodPrivate(string $className, string $methodName): bool
600600
{
601601
$className = $this->prepareClassReflectionForUsage($className);
602-
return (isset($this->classReflectionData[$className][self::DATA_CLASS_METHODS][$methodName][self::DATA_METHOD_VISIBILITY]) && $this->classReflectionData[$className][self::DATA_CLASS_METHODS][$methodName][self::DATA_METHOD_VISIBILITY] === self::VISIBILITY_PRIVATE);
602+
return ($this->classReflectionData[$className][self::DATA_CLASS_METHODS][$methodName][self::DATA_METHOD_VISIBILITY] ?? null) === self::VISIBILITY_PRIVATE;
603603
}
604604

605605
/**
@@ -721,7 +721,7 @@ public function getMethodAnnotation(string $className, string $methodName, strin
721721
public function getClassPropertyNames(string $className): array
722722
{
723723
$className = $this->prepareClassReflectionForUsage($className);
724-
return isset($this->classReflectionData[$className][self::DATA_CLASS_PROPERTIES]) ? array_keys($this->classReflectionData[$className][self::DATA_CLASS_PROPERTIES]) : [];
724+
return array_keys($this->classReflectionData[$className][self::DATA_CLASS_PROPERTIES] ?? []);
725725
}
726726

727727
/**
@@ -806,12 +806,9 @@ public function getMethodDeclaredReturnType(string $className, string $methodNam
806806
public function getPropertyNamesByTag(string $className, string $tag): array
807807
{
808808
$className = $this->prepareClassReflectionForUsage($className);
809-
if (!isset($this->classReflectionData[$className][self::DATA_CLASS_PROPERTIES])) {
810-
return [];
811-
}
812809

813810
$propertyNames = [];
814-
foreach ($this->classReflectionData[$className][self::DATA_CLASS_PROPERTIES] as $propertyName => $propertyData) {
811+
foreach ($this->classReflectionData[$className][self::DATA_CLASS_PROPERTIES] ?? [] as $propertyName => $propertyData) {
815812
if (isset($propertyData[self::DATA_PROPERTY_TAGS_VALUES][$tag])) {
816813
$propertyNames[$propertyName] = true;
817814
}
@@ -834,10 +831,6 @@ public function getPropertyNamesByTag(string $className, string $tag): array
834831
public function getPropertyTagsValues(string $className, string $propertyName): array
835832
{
836833
$className = $this->prepareClassReflectionForUsage($className);
837-
if (!isset($this->classReflectionData[$className][self::DATA_CLASS_PROPERTIES][$propertyName])) {
838-
return [];
839-
}
840-
841834
return $this->classReflectionData[$className][self::DATA_CLASS_PROPERTIES][$propertyName][self::DATA_PROPERTY_TAGS_VALUES] ?? [];
842835
}
843836

@@ -857,10 +850,6 @@ public function getPropertyTagsValues(string $className, string $propertyName):
857850
public function getPropertyTagValues(string $className, string $propertyName, string $tag): array
858851
{
859852
$className = $this->prepareClassReflectionForUsage($className);
860-
if (!isset($this->classReflectionData[$className][self::DATA_CLASS_PROPERTIES][$propertyName])) {
861-
return [];
862-
}
863-
864853
return $this->classReflectionData[$className][self::DATA_CLASS_PROPERTIES][$propertyName][self::DATA_PROPERTY_TAGS_VALUES][$tag] ?? [];
865854
}
866855

@@ -892,8 +881,7 @@ public function getPropertyType(string $className, string $propertyName): ?strin
892881
public function isPropertyPrivate(string $className, string $propertyName): bool
893882
{
894883
$className = $this->prepareClassReflectionForUsage($className);
895-
return (isset($this->classReflectionData[$className][self::DATA_CLASS_PROPERTIES][$propertyName][self::DATA_PROPERTY_VISIBILITY])
896-
&& $this->classReflectionData[$className][self::DATA_CLASS_PROPERTIES][$propertyName][self::DATA_PROPERTY_VISIBILITY] === self::VISIBILITY_PRIVATE);
884+
return ($this->classReflectionData[$className][self::DATA_CLASS_PROPERTIES][$propertyName][self::DATA_PROPERTY_VISIBILITY] ?? null) === self::VISIBILITY_PRIVATE;
897885
}
898886

899887
/**
@@ -947,12 +935,9 @@ public function isPropertyAnnotatedWith(string $className, string $propertyName,
947935
public function getPropertyNamesByAnnotation(string $className, string $annotationClassName): array
948936
{
949937
$className = $this->prepareClassReflectionForUsage($className);
950-
if (!isset($this->classReflectionData[$className][self::DATA_CLASS_PROPERTIES])) {
951-
return [];
952-
}
953938

954939
$propertyNames = [];
955-
foreach ($this->classReflectionData[$className][self::DATA_CLASS_PROPERTIES] as $propertyName => $propertyData) {
940+
foreach ($this->classReflectionData[$className][self::DATA_CLASS_PROPERTIES] ?? [] as $propertyName => $propertyData) {
956941
if (isset($propertyData[self::DATA_PROPERTY_ANNOTATIONS][$annotationClassName])) {
957942
$propertyNames[$propertyName] = true;
958943
}

0 commit comments

Comments
 (0)