Skip to content

Commit 8e64e0c

Browse files
committed
TASK: Adjust phpstan config to apply level 8 rules to the Flow/Security context and remove breaking changes
Some return type Annotations in the ObjectManagerInterface are adjusted to match the reality already to prevent false errors beeing reported by PhpStan
1 parent 492b270 commit 8e64e0c

File tree

15 files changed

+55
-41
lines changed

15 files changed

+55
-41
lines changed

Neos.Flow/Classes/ObjectManagement/ObjectManagerInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public function getObjectNameByClassName($className);
110110
* Returns the implementation class name for the specified object
111111
*
112112
* @param string $objectName The object name
113-
* @return string The class name corresponding to the given object name or false if no such object is registered
113+
* @return string|false The class name corresponding to the given object name or false if no such object is registered
114114
* @api
115115
*/
116116
public function getClassNameByObjectName($objectName);
@@ -119,7 +119,7 @@ public function getClassNameByObjectName($objectName);
119119
* Returns the key of the package the specified object is contained in.
120120
*
121121
* @param string $objectName The object name
122-
* @return string The package key or false if no such object exists
122+
* @return string|false The package key or false if no such object exists
123123
*/
124124
public function getPackageKeyByObjectName($objectName);
125125

Neos.Flow/Classes/Security/Aspect/LoggingAspect.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class LoggingAspect
5050
public function logManagerAuthenticate(JoinPointInterface $joinPoint)
5151
{
5252
if ($joinPoint->hasException()) {
53+
/** @var \Exception $exception */
5354
$exception = $joinPoint->getException();
5455
if (!$exception instanceof NoTokensAuthenticatedException) {
5556
$this->securityLogger->notice(sprintf('Authentication failed: "%s" #%d', $exception->getMessage(), $exception->getCode()), $this->getLogEnvironmentFromJoinPoint($joinPoint));

Neos.Flow/Classes/Security/Authentication/AuthenticationProviderResolver.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,12 @@ public function __construct(ObjectManagerInterface $objectManager)
4747
public function resolveProviderClass($providerName)
4848
{
4949
$className = $this->objectManager->getClassNameByObjectName($providerName);
50-
if ($className !== false && is_subclass_of($className, AuthenticationProviderInterface::class)) {
50+
if (is_string($className) && is_subclass_of($className, AuthenticationProviderInterface::class)) {
5151
return $className;
5252
}
5353

5454
$className = $this->objectManager->getClassNameByObjectName('Neos\Flow\Security\Authentication\Provider\\' . $providerName);
55-
if ($className !== false && is_subclass_of($className, AuthenticationProviderInterface::class)) {
55+
if (is_string($className) && is_subclass_of($className, AuthenticationProviderInterface::class)) {
5656
return $className;
5757
}
5858

Neos.Flow/Classes/Security/Authentication/Provider/FileBasedSimpleKeyProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public function authenticate(TokenInterface $authenticationToken)
107107
protected function validateCredentials(PasswordTokenInterface $authenticationToken): void
108108
{
109109
$key = $this->fileBasedSimpleKeyService->getKey($this->options['keyName']);
110-
if (!$this->hashService->validatePassword($authenticationToken->getPassword(),$key)) {
110+
if (!$this->hashService->validatePassword($authenticationToken->getPassword(), $key)) {
111111
$authenticationToken->setAuthenticationStatus(TokenInterface::WRONG_CREDENTIALS);
112112
return;
113113
}

Neos.Flow/Classes/Security/Authorization/Interceptor/PolicyEnforcement.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ public function invoke()
9696

9797
try {
9898
$this->authenticationManager->authenticate();
99+
/** @phpstan-ignore catch.neverThrown */
99100
} catch (EntityNotFoundException $exception) {
100101
throw new AuthenticationRequiredException('Could not authenticate. Looks like a broken session.', 1358971444, $exception);
101102
} catch (NoTokensAuthenticatedException $noTokensAuthenticatedException) {

Neos.Flow/Classes/Security/Authorization/Privilege/Entity/Doctrine/EntityPrivilege.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
* source code.
1212
*/
1313

14-
use Doctrine\Persistence\Mapping\ClassMetadata;
1514
use Doctrine\ORM\EntityManager;
1615
use Doctrine\ORM\EntityManagerInterface;
1716
use Neos\Eel\Context as EelContext;

Neos.Flow/Classes/Security/Authorization/Privilege/Entity/Doctrine/EntityPrivilegeExpressionParser.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@ class EntityPrivilegeExpressionParser extends CompilingEelParser
2525
/**
2626
* @param array<string,mixed> $result
2727
* @param array<string,mixed> $sub
28+
* @return void
2829
*/
29-
public function NotExpression_exp(&$result, $sub): void
30+
public function NotExpression_exp(&$result, $sub)
3031
{
3132
if (!isset($result['code'])) {
3233
$result['code'] = '$context';
@@ -37,27 +38,30 @@ public function NotExpression_exp(&$result, $sub): void
3738
/**
3839
* @param array<string,mixed> $result
3940
* @param array<string,mixed> $sub
41+
* @return void
4042
*/
41-
public function Disjunction_rgt(&$result, $sub): void
43+
public function Disjunction_rgt(&$result, $sub)
4244
{
4345
$result['code'] = '$context->callAndWrap(\'disjunction\', array(' . $this->unwrapExpression($result['code']) . ', ' . $this->unwrapExpression($sub['code']) . '))';
4446
}
4547

4648
/**
4749
* @param array<string,mixed> $result
4850
* @param array<string,mixed> $sub
51+
* @return void
4952
*/
50-
public function Conjunction_rgt(&$result, $sub): void
53+
public function Conjunction_rgt(&$result, $sub)
5154
{
5255
$result['code'] = '$context->callAndWrap(\'conjunction\', array(' . $this->unwrapExpression($result['code']) . ', ' . $this->unwrapExpression($sub['code']) . '))';
5356
}
5457

5558
/**
5659
* @param array<string,mixed> $result
5760
* @param array<string,mixed> $sub
61+
* @return void
5862
* @throws ParserException
5963
*/
60-
public function Comparison_rgt(&$result, $sub): void
64+
public function Comparison_rgt(&$result, $sub)
6165
{
6266
$lval = $result['code'];
6367
$rval = $sub['code'];

Neos.Flow/Classes/Security/Authorization/Privilege/Entity/Doctrine/PropertyConditionGenerator.php

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,8 @@ public function getSql(DoctrineSqlFilter $sqlFilter, ORMClassMetadata $targetEnt
254254
} elseif ($targetEntity->isSingleValuedAssociation($targetEntityPropertyName) === true && $targetEntity->isAssociationInverseSide($targetEntityPropertyName) === true) {
255255
throw new InvalidQueryRewritingConstraintException(
256256
'Single valued properties from the inverse side are not supported in a content security constraint path! Got: "'
257-
. $this->path . ' ' . $this->operator . ' ' . json_encode($this->operandDefinition) . '"'
258-
, 1416397754
257+
. $this->path . ' ' . $this->operator . ' ' . json_encode($this->operandDefinition) . '"',
258+
1416397754
259259
);
260260
} elseif ($targetEntity->isCollectionValuedAssociation($targetEntityPropertyName) === true) {
261261
return $this->getSqlForPropertyContains($sqlFilter, $quoteStrategy, $targetEntity, $targetTableAlias, $targetEntityPropertyName);
@@ -381,19 +381,13 @@ protected function getSqlForManyToOneAndOneToOneRelationsWithoutPropertyPath(Doc
381381
$currentReferencedOperandName = $operandAlias . $joinColumn['referencedColumnName'];
382382
if (is_object($this->operand)) {
383383
$type = TypeHandling::getTypeForValue($this->operand);
384-
if ($type === false) {
385-
throw new \Exception('Could not resolve type for ' . get_debug_type($this->operand), 1743930563);
386-
}
387384
$operandMetadataInfo = $this->entityManager->getClassMetadata($type);
388385
$currentReferencedValueOfOperand = $operandMetadataInfo->getFieldValue($this->operand, $operandMetadataInfo->getFieldForColumn($joinColumn['referencedColumnName']));
389386
$this->setParameter($sqlFilter, $currentReferencedOperandName, $currentReferencedValueOfOperand, $associationMapping['type']);
390387
} elseif (is_array($this->operandDefinition)) {
391388
foreach ($this->operandDefinition as $operandIterator => $singleOperandValue) {
392389
if (is_object($singleOperandValue)) {
393390
$type = TypeHandling::getTypeForValue($singleOperandValue);
394-
if ($type === false) {
395-
throw new \Exception('Could not resolve type for ' . get_debug_type($singleOperandValue), 1743930566);
396-
}
397391
$operandMetadataInfo = $this->entityManager->getClassMetadata($type);
398392
$currentReferencedValueOfOperand = $operandMetadataInfo->getFieldValue($singleOperandValue, $operandMetadataInfo->getFieldForColumn($joinColumn['referencedColumnName']));
399393
$this->setParameter($sqlFilter, $operandIterator, $currentReferencedValueOfOperand, $associationMapping['type']);
@@ -466,6 +460,7 @@ protected function getSubselectQuery(ClassMetadata $targetEntity, $targetEntityP
466460
$subselectConstraint = $subselectQuery->equals($propertyName, $this->operand);
467461
break;
468462
case '!=':
463+
/** @phpstan-ignore argument.type */
469464
$subselectConstraint = $subselectQuery->logicalNot($subselectQuery->equals($propertyName, $this->operand));
470465
break;
471466
case '<':
@@ -489,7 +484,7 @@ protected function getSubselectQuery(ClassMetadata $targetEntity, $targetEntityP
489484
default:
490485
throw new \Exception(sprintf('Invalid operator "%s".', $this->operator), 1699025734);
491486
}
492-
487+
/** @phpstan-ignore argument.type */
493488
$subselectQuery->matching($subselectConstraint);
494489
return $subselectQuery;
495490
}

Neos.Flow/Classes/Security/Cryptography/HashService.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,11 @@ public function injectSettings(array $settings)
7272
* @return string The hash of the string
7373
* @throws InvalidArgumentForHashGenerationException if something else than a string was given as parameter
7474
*/
75-
public function generateHmac(string $string): string
75+
public function generateHmac($string)
7676
{
77+
if (!is_string($string)) {
78+
throw new InvalidArgumentForHashGenerationException('A hash can only be generated for a string, but "' . gettype($string) . '" was given.', 1255069587);
79+
}
7780
return hash_hmac('sha1', $string, $this->getEncryptionKey());
7881
}
7982

@@ -117,8 +120,11 @@ public function validateHmac($string, $hmac)
117120
* @throws InvalidHashException if the hash did not fit to the data.
118121
* @todo Mark as API once it is more stable
119122
*/
120-
public function validateAndStripHmac(string $string): string
123+
public function validateAndStripHmac($string)
121124
{
125+
if (!is_string($string)) {
126+
throw new InvalidArgumentForHashGenerationException('A hash can only be validated for a string, but "' . gettype($string) . '" was given.', 1320829762);
127+
}
122128
if (strlen($string) < 40) {
123129
throw new InvalidArgumentForHashGenerationException('A hashed string must contain at least 40 characters, the given string was only ' . strlen($string) . ' characters long.', 1320830276);
124130
}

Neos.Flow/Classes/Security/Cryptography/RsaWalletServiceInterface.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function registerPublicKeyFromString($publicKeyString);
5454
* @return OpenSslRsaKey The public key
5555
* @throws InvalidKeyPairIdException If the given fingerprint identifies no valid key pair
5656
*/
57-
public function getPublicKey(string $fingerprint): OpenSslRsaKey;
57+
public function getPublicKey($fingerprint);
5858

5959
/**
6060
* Decrypts the given cypher with the private key identified by the given fingerprint
@@ -67,7 +67,7 @@ public function getPublicKey(string $fingerprint): OpenSslRsaKey;
6767
* @throws InvalidKeyPairIdException If the given fingerprint identifies no valid keypair
6868
* @throws DecryptionNotAllowedException If the given fingerprint identifies a keypair for encrypted passwords
6969
*/
70-
public function decrypt(string $cypher, string $fingerprint): string;
70+
public function decrypt($cypher, $fingerprint);
7171

7272
/**
7373
* Signs the given plaintext with the private key identified by the given fingerprint
@@ -77,7 +77,7 @@ public function decrypt(string $cypher, string $fingerprint): string;
7777
* @return string The signature of the given plaintext
7878
* @throws InvalidKeyPairIdException If the given fingerprint identifies no valid keypair
7979
*/
80-
public function sign(string $plaintext, string $fingerprint): string;
80+
public function sign($plaintext, $fingerprint);
8181

8282
/**
8383
* Checks whether the given signature is valid for the given plaintext
@@ -88,7 +88,7 @@ public function sign(string $plaintext, string $fingerprint): string;
8888
* @param string $fingerprint The fingerprint to identify to correct public key
8989
* @return boolean true if the signature is correct for the given plaintext and public key
9090
*/
91-
public function verifySignature(string $plaintext, string $signature, string $fingerprint): bool;
91+
public function verifySignature($plaintext, $signature, $fingerprint);
9292

9393
/**
9494
* Encrypts the given plaintext with the public key identified by the given fingerprint
@@ -109,12 +109,14 @@ public function encryptWithPublicKey($plaintext, $fingerprint);
109109
* @param string $fingerprint The fingerprint to identify to correct private key
110110
* @return boolean true if the password is correct
111111
*/
112-
public function checkRSAEncryptedPassword(string $encryptedPassword, string $passwordHash, string $salt, string $fingerprint): bool;
112+
public function checkRSAEncryptedPassword($encryptedPassword, $passwordHash, $salt, $fingerprint);
113113

114114
/**
115115
* Destroys the keypair identified by the given fingerprint
116116
*
117+
* @param string $fingerprint
118+
* @return void
117119
* @throws InvalidKeyPairIdException If the given fingerprint identifies no valid key pair
118120
*/
119-
public function destroyKeypair(string $fingerprint): void;
121+
public function destroyKeypair($fingerprint);
120122
}

0 commit comments

Comments
 (0)