Skip to content

Commit

Permalink
fix phpstan issues
Browse files Browse the repository at this point in the history
  • Loading branch information
solverat committed Dec 18, 2024
1 parent a6145af commit 2c6ba8e
Show file tree
Hide file tree
Showing 13 changed files with 19 additions and 53 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"require": {
"pimcore/pimcore": "^11.0",
"doctrine/orm": "^2.7",
"symfony/form": "^6.2"
"symfony/form": "^6.4"
},
"require-dev": {
"codeception/codeception": "^5.0",
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/ResettingController.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function sendEmailAction(Request $request): Response
{
$username = $request->request->get('username');

/** @var UserInterface $user */
/** @var UserInterface|null $user */
$user = $this->userManager->findUserByUsernameOrEmail($username);

/* Dispatch init event */
Expand Down
2 changes: 1 addition & 1 deletion src/CoreExtension/GroupMultiselect.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ protected function prepareDataForPersistence(array|Element\ElementInterface $dat
return $return;
}

if (is_array($data) && count($data) === 0) {
if (is_array($data)) {
//give empty array if data was not null
return [];
}
Expand Down
8 changes: 4 additions & 4 deletions src/Document/Builder/BrickBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Symfony\Component\Security\Core\Exception\AuthenticationException;
use Symfony\Bundle\SecurityBundle\Security;
use Symfony\Component\Security\Http\SecurityRequestAttributes;
use Twig\Environment;

class BrickBuilder
Expand Down Expand Up @@ -122,13 +122,13 @@ public function getViewParams(): array
//only show backend note
$template = $this->getTemplate('area-not-available');
} elseif (!$this->tokenStorage->getToken()?->getUser() instanceof UserInterface) {
$authErrorKey = Security::AUTHENTICATION_ERROR;
$lastUsernameKey = Security::LAST_USERNAME;
$authErrorKey = SecurityRequestAttributes::AUTHENTICATION_ERROR;
$lastUsernameKey = SecurityRequestAttributes::LAST_USERNAME;

// get the error if any (works with forward and redirect -- see below)
if ($this->request->attributes->has($authErrorKey)) {
$error = $this->request->attributes->get($authErrorKey);
} elseif (null !== $this->request->getSession() && $this->request->getSession()->has($authErrorKey)) {
} elseif ($this->request->getSession()->has($authErrorKey)) {
$error = $this->request->getSession()->get($authErrorKey);
$this->request->getSession()->remove($authErrorKey);
} else {
Expand Down
9 changes: 3 additions & 6 deletions src/Manager/ClassManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@ public function __construct(protected Configuration $configuration)

public function getGroupListing(): Listing
{
/** @var AbstractObject $listingClass */
$listingClass = $this->getGroupClass();

if (!Tool::classExists($listingClass)) {
if (!Tool::classExists($listingClass) || !method_exists($listingClass, 'getList')) {
throw new \Exception(sprintf('Cannot create listing with class "%s"', $listingClass));
}

Expand All @@ -27,10 +26,9 @@ public function getGroupListing(): Listing

public function getUserListing(): Listing
{
/** @var AbstractObject $listingClass */
$listingClass = $this->getUserClass();

if (!Tool::classExists($listingClass)) {
if (!Tool::classExists($listingClass) || !method_exists($listingClass, 'getList')) {
throw new \Exception(sprintf('Cannot create listing with class "%s"', $listingClass));
}

Expand All @@ -39,10 +37,9 @@ public function getUserListing(): Listing

public function getSsoIdentityListing(): Listing
{
/** @var AbstractObject $listingClass */
$listingClass = $this->getSsoIdentityClass();

if (!Tool::classExists($listingClass)) {
if (!Tool::classExists($listingClass) || !method_exists($listingClass, 'getList')) {
throw new \Exception(sprintf('Cannot create listing with class "%s"', $listingClass));
}

Expand Down
11 changes: 2 additions & 9 deletions src/Manager/RestrictionManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,7 @@ public function getElementRestrictedGroups(ElementInterface $element): array
return $groups;
}

$groups = [];
if (is_array($restriction->getRelatedGroups())) {
$groups = $restriction->getRelatedGroups();
}

return $groups;
return $restriction->getRelatedGroups();
}

public function getElementRestrictionStatus(ElementInterface $element): ElementRestriction
Expand Down Expand Up @@ -88,9 +83,7 @@ public function getElementRestrictionStatus(ElementInterface $element): ElementR
return $elementRestriction;
}

if (is_array($restriction->getRelatedGroups())) {
$elementRestriction->setRestrictionGroups($restriction->getRelatedGroups());
}
$elementRestriction->setRestrictionGroups($restriction->getRelatedGroups());

//check if user is not logged in.
if (!$user instanceof UserInterface) {
Expand Down
3 changes: 1 addition & 2 deletions src/Manager/SsoIdentityManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public function createSsoIdentity(UserInterface $user, string $provider, string
$key = File::getValidFilename(sprintf('%s-%s', $provider, $identifier));
$path = sprintf('%s/%s', $user->getRealFullPath(), $key);

/** @var SsoIdentityInterface $ssoIdentity */
/** @var SsoIdentityInterface|null $ssoIdentity */
$ssoIdentity = DataObject::getByPath($path);

if (!$ssoIdentity instanceof SsoIdentityInterface) {
Expand Down Expand Up @@ -158,7 +158,6 @@ protected function findSsoIdentity(string $provider, string $identifier): ?SsoId

protected function findUserBySsoIdentity(SsoIdentityInterface $ssoIdentity): ?UserInterface
{
/** @var DataObject\Concrete $userClass */
$userClass = $this->classManager->getUserClass();

$qb = $this->connection->createQueryBuilder();
Expand Down
14 changes: 3 additions & 11 deletions src/Restriction/Dao.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,20 +80,12 @@ public function save()
return true;
}

/**
* @param array $data
*
* @return mixed
* @throws Exception
*/
private function addRelationData($data)
private function addRelationData(array $data): array
{
$relations = $this->db->fetchAllAssociative('SELECT * FROM ' . $this->tableRelationName . ' WHERE restrictionId = ?', [$data['id']]);

if ($relations !== false) {
foreach ($relations as $relation) {
$data['relatedGroups'][] = $relation['groupId'];
}
foreach ($relations as $relation) {
$data['relatedGroups'][] = $relation['groupId'];
}

return $data;
Expand Down
4 changes: 2 additions & 2 deletions src/Service/RequestPropertiesForUserExtractorService.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ public function extractFromParameterBag(array $parameter): array
{
$userProperties = [];

if (isset($parameter['locale']) && $parameter['locale'] !== null) {
if (isset($parameter['locale'])) {
$userProperties['_user_locale'] = $parameter['locale'];
}

if (isset($parameter['site_id']) && $parameter['site_id'] !== null) {
if (isset($parameter['site_id'])) {
$site = Site::getById($parameter['site_id']);
if ($site instanceof Site) {
$userProperties['_site_domain'] = $site->getMainDomain();
Expand Down
4 changes: 0 additions & 4 deletions src/Service/ResourceMappingService.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,6 @@ public function addDefaults(UserInterface $user, ResourceOwnerInterface $resourc
$ownerDetails = $resourceOwner->toArray();
$disallowedProperties = ['lastLogin', 'password', 'confirmationToken', 'passwordRequestedAt', 'groups', 'ssoIdentities'];

if (!is_array($ownerDetails)) {
return;
}

foreach ($ownerDetails as $property => $value) {
if (in_array(strtolower($property), $disallowedProperties)) {
continue;
Expand Down
5 changes: 1 addition & 4 deletions src/Service/SsoIdentityStatusService.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,7 @@ protected function determinateDeletionByDefaults(UserInterface $user): bool

// don't touch a user if he has other identities
$userSsoIdentities = $this->ssoIdentityManager->getSsoIdentities($user);
if (is_array($userSsoIdentities) && count($userSsoIdentities) > 0) {
return false;
}

return true;
return count($userSsoIdentities) <= 0;
}
}
4 changes: 0 additions & 4 deletions src/Twig/Extension/OAuthExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,6 @@ public function getSocialLinks(string $route = 'members_user_security_oauth_logi
$ssoIdentityProviders = $this->getSsoIdentityProvider();
$resourceOwners = $this->oauthRegistry->getEnabledClientKeys();

if (!is_array($resourceOwners)) {
return [];
}

$data = [];

foreach ($resourceOwners as $resourceOwner) {
Expand Down
4 changes: 0 additions & 4 deletions src/Validator/Constraints/PimcoreUniqueEntityValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ public function validate($entity, Constraint $constraint): void
throw new UnexpectedTypeException($constraint, __NAMESPACE__ . '\PimcoreUniqueEntity');
}

if (!is_array($constraint->fields)) {
throw new UnexpectedTypeException($constraint->fields, 'array');
}

$fields = $constraint->fields;

if (count($fields) === 0) {
Expand Down

0 comments on commit 2c6ba8e

Please # to comment.