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 5, 2024
1 parent 21b3aaf commit a061c91
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 46 deletions.
4 changes: 3 additions & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ parameters:
reportUnmatchedIgnoredErrors: false
symfony:
containerXmlPath: %currentWorkingDirectory%/var/cache/test/TestKernelTestDebugContainer.xml
constantHassers: false
constantHassers: false
ignoreErrors:
- '#Trait SocialDataBundle\\Controller\\Admin\\Traits\\ConnectResponseTrait is used zero times and is not analysed\.#'
30 changes: 12 additions & 18 deletions src/Builder/ExtJsDataBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,13 @@

class ExtJsDataBuilder
{
protected NormalizerInterface $serializer;
protected Translator $translator;
protected ConnectorManagerInterface $connectorManager;
protected WallManagerInterface $wallManager;
protected StatisticServiceInterface $statisticService;

public function __construct(
NormalizerInterface $serializer,
Translator $translator,
ConnectorManagerInterface $connectorManager,
WallManagerInterface $wallManager,
StatisticServiceInterface $statisticService
protected NormalizerInterface $serializer,
protected Translator $translator,
protected ConnectorManagerInterface $connectorManager,
protected WallManagerInterface $wallManager,
protected StatisticServiceInterface $statisticService
) {
$this->serializer = $serializer;
$this->translator = $translator;
$this->connectorManager = $connectorManager;
$this->wallManager = $wallManager;
$this->statisticService = $statisticService;
}

public function generateConnectorListData(): array
Expand Down Expand Up @@ -163,13 +152,18 @@ public function generateFormErrorList(FormInterface $form): array
{
$errors = [];

/** @var FormError $e */
foreach ($form->getErrors(true, true) as $e) {

if (!$e instanceof FormError) {
continue;
}

$errorMessageTemplate = $e->getMessageTemplate();
foreach ($e->getMessageParameters() as $key => $value) {
$errorMessageTemplate = str_replace($key, $value, $errorMessageTemplate);
}
$errors[] = sprintf('%s: %s', $e->getOrigin()->getConfig()->getName(), $errorMessageTemplate);

$errors[] = sprintf('%s: %s', $e->getOrigin()?->getConfig()->getName(), $errorMessageTemplate);
}

return $errors;
Expand Down
7 changes: 5 additions & 2 deletions src/Controller/Admin/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,13 @@ public function saveConnectorConfigurationAction(Request $request, string $conne

$connectorDefinition = $this->connectorManager->getConnectorDefinition($connectorName, true);

/** @var ConnectorEngineConfigurationInterface $class */
$formType = '';
$class = $connectorDefinition->getEngineConfigurationClass();
if (is_string($class) && is_subclass_of($class, ConnectorEngineConfigurationInterface::class)) {
$formType = $class::getFormClass();
}

$form = $this->formFactory->create($class::getFormClass(), $connectorDefinition->getEngineConfiguration());
$form = $this->formFactory->create($formType, $connectorDefinition->getEngineConfiguration());

$form->submit($configuration);

Expand Down
3 changes: 0 additions & 3 deletions src/Event/SocialPostBuildConfigureEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ public function getBuildConfig(): BuildConfig
return $this->buildConfig;
}

/**
* @throws \Exception
*/
public function setOption(mixed $key, mixed $value): void
{
$this->options[$key] = $value;
Expand Down
7 changes: 5 additions & 2 deletions src/Form/Admin/Type/Wall/FeedType.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,13 @@ public function addConfigurationField(FormEvent $event): void
throw new InvalidConfigurationException(sprintf('No Connector definition found for engine "%s"', $connectorEngine->getName()));
}

/** @var ConnectorFeedConfigurationInterface $class */
$formType = '';
$class = $connectorDefinition->getFeedConfigurationClass();
if (is_subclass_of($class, ConnectorFeedConfigurationInterface::class)) {
$formType = $class::getFormClass();
}

$form->add('configuration', $class::getFormClass());
$form->add('configuration', $formType);
}

public function configureOptions(OptionsResolver $resolver): void
Expand Down
4 changes: 0 additions & 4 deletions src/Manager/ConnectorManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,6 @@ public function getConnectorDefinition(string $connectorDefinitionName, bool $lo
return null;
}

if (!$connectorDefinition instanceof ConnectorDefinitionInterface) {
return null;
}

if ($loadEngine === true) {
$connectorEngine = $this->connectorEngineRepository->findByName($connectorDefinitionName);
$connectorDefinition->setConnectorEngine($connectorEngine);
Expand Down
2 changes: 1 addition & 1 deletion src/Manager/SocialPostManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ protected function persistMedia(FeedInterface $feed, SocialPostInterface $social

// 2. forced mode enabled or new asset
// => add new data or try to add new version if data has changed!
if ($isNewAsset === false && $forceProcessing === true && md5($asset->getData()) === md5($imageData['content'])) {
if ($forceProcessing === true && md5($asset->getData()) === md5($imageData['content'])) {
$socialPost->setPoster($asset);
$this->logger->debug(
sprintf('Asset %s for post %s forced update skipped since no data has been changed', $asset->getFilename(), $socialPost->getSocialId()),
Expand Down
14 changes: 2 additions & 12 deletions src/Processor/SocialPostBuilderProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,6 @@ protected function processWall(WallInterface $wall, bool $forceProcessing): void
protected function processFeed(FeedInterface $feed, bool $forceProcessing): void
{
$connectorEngine = $feed->getConnectorEngine();
if (!$connectorEngine instanceof ConnectorEngineInterface) {
// @todo: dispatch notification?
return;
}

if (!$connectorEngine->isEnabled()) {
// @todo: dispatch notification?
Expand Down Expand Up @@ -146,14 +142,7 @@ protected function loadFeedPosts(string $connectorName, BuildConfig $buildConfig
return [];
}

$fetchedItems = $fetchData->getFetchedEntities();

if (!is_array($fetchedItems)) {
$this->logger->debug(sprintf('No elements found during fetch process'), $logContext);
return [];
}

foreach ($fetchedItems as $entry) {
foreach ($fetchData->getFetchedEntities() as $entry) {

// 2 filter
$filterData = $this->dispatchSocialPostBuildCycle('filter', $connectorName, $buildConfig, $postBuilder, [
Expand Down Expand Up @@ -185,6 +174,7 @@ protected function loadFeedPosts(string $connectorName, BuildConfig $buildConfig
continue;
}

/* @phpstan-ignore-next-line */
if (!$preFetchedSocialPostEntity instanceof SocialPostInterface) {
$this->logger->error(sprintf('Could not resolve pre-fetched social post for entity with id "%s"', $filteredId), $logContext);
continue;
Expand Down
9 changes: 6 additions & 3 deletions src/Repository/SocialPostRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,14 +230,17 @@ public function deleteOutdatedSocialPosts(int $expireDays, bool $deletePoster =
} catch (\Exception $e) {
// fail silently
}

}
}

public function getClassId(): string
{
/** @var Concrete $concreteObject */
$concreteObject = sprintf('\Pimcore\Model\DataObject\%s', ucfirst($this->environmentService->getSocialPostDataClass()));
$dataClassName = ucfirst($this->environmentService->getSocialPostDataClass());
$concreteObject = sprintf('\Pimcore\Model\DataObject\%s', $dataClassName);

if (!is_subclass_of($concreteObject, Concrete::class)) {
throw new \Exception(sprintf('Invalid data object class "%s"', $dataClassName));
}

return $concreteObject::classId();
}
Expand Down

0 comments on commit a061c91

Please sign in to comment.