Skip to content
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

Feature/evaluator enabler #445

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace EvaluatorExtension\Adapters;

class EvaluatorExecutor
{

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace EvaluatorExtension\DependencyInjection;

use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\Extension;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;

class EvaluatorExtensionExtension extends Extension
{
/**
* @param array $configs
* @param ContainerBuilder $container
* @return void
* @throws \Exception
*/
public function load(array $configs, ContainerBuilder $container): void
{
$this->createYamlFileLoader($container)->load('services.yaml');
}

/**
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
*
* @return \Symfony\Component\DependencyInjection\Loader\YamlFileLoader
*/
protected function createYamlFileLoader(ContainerBuilder $container): YamlFileLoader
{
return new YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
}
}
15 changes: 15 additions & 0 deletions extension/EvaluatorExtension/src/EvaluatorExtensionBundle.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace EvaluatorExtension;

use EvaluatorExtension\DependencyInjection\EvaluatorExtensionExtension;
use Symfony\Component\DependencyInjection\Extension\Extension;
use Symfony\Component\HttpKernel\Bundle\Bundle;

class EvaluatorExtensionBundle extends Bundle
{
public function createContainerExtension(): Extension
{
return new EvaluatorExtensionExtension();
}
}
12 changes: 12 additions & 0 deletions extension/EvaluatorExtension/src/Resources/config/services.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
parameters:
minimum_allowed_shop_version_checker_file: '%kernel.project_dir%/vendor/spryker-sdk/evaluator/data/minimum-allowed-package-versions.json'
services:
_defaults:
autowire: true
autoconfigure: true

EvaluatorExtension\:
resource: '../../../src/*'

EvaluatorExtension\Task\EvaluateTask:
tags: [ 'sdk.task' ]
82 changes: 82 additions & 0 deletions extension/EvaluatorExtension/src/Task/Command/EvaluateCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?php

namespace EvaluatorExtension\Task\Command;

use SprykerSdk\Evaluator\Dto\EvaluatorInputDataDto;
use SprykerSdk\Evaluator\Executor\EvaluatorExecutorInterface;
use SprykerSdk\Sdk\Core\Domain\Entity\Message;
use SprykerSdk\SdkContracts\Entity\ContextInterface;
use SprykerSdk\SdkContracts\Entity\ConverterInterface;
use SprykerSdk\SdkContracts\Entity\ExecutableCommandInterface;
use SprykerSdk\SdkContracts\Entity\MessageInterface;

class
EvaluateCommand implements ExecutableCommandInterface
{

protected EvaluatorExecutorInterface $evaluatorExecutor;

/**
* @param EvaluatorExecutorInterface $evaluatorExecutor
*/
public function __construct(EvaluatorExecutorInterface $evaluatorExecutor)
{
$this->evaluatorExecutor = $evaluatorExecutor;
}

public function getCommand(): string
{
return static::class;
}

public function getType(): string
{
return 'php';
}

public function getTags(): array
{
return [];
}

public function hasStopOnError(): bool
{
return true;
}

public function getConverter(): ?ConverterInterface
{
return null;
}

public function getStage(): string
{
return ContextInterface::DEFAULT_STAGE;
}

public function execute(ContextInterface $context): ContextInterface
{
$dto = new EvaluatorInputDataDto('/project');
$response = $this->evaluatorExecutor->execute($dto);
if ($response->isSuccessful()) {
$context->setExitCode(0);

return $context;
}

foreach ($response->getReportLines() as $reportLines) {
foreach ($reportLines->getViolations() as $key => $violation) {
$context->addMessage($reportLines->getCheckerName() . $key,
new Message($violation->getMessage(), MessageInterface::ERROR)
);
}
if ($reportLines->getViolations() && $reportLines->getDocUrl() !== '') {
$context->addMessage(
$reportLines->getCheckerName() . '__doclink__',
new Message($reportLines->getDocUrl(), MessageInterface::ERROR)
);
}
}
return $context;
}
}
87 changes: 87 additions & 0 deletions extension/EvaluatorExtension/src/Task/EvaluateTask.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?php

namespace EvaluatorExtension\Task;

use EvaluatorExtension\Task\Command\EvaluateCommand;
use SprykerSdk\Evaluator\Executor\EvaluatorExecutorInterface;
use SprykerSdk\Sdk\Core\Domain\Entity\Lifecycle\InitializedEventData;
use SprykerSdk\Sdk\Core\Domain\Entity\Lifecycle\Lifecycle;
use SprykerSdk\Sdk\Core\Domain\Entity\Lifecycle\RemovedEventData;
use SprykerSdk\Sdk\Core\Domain\Entity\Lifecycle\UpdatedEventData;
use SprykerSdk\SdkContracts\Entity\Lifecycle\LifecycleInterface;
use SprykerSdk\SdkContracts\Entity\TaskInterface;

class
EvaluateTask implements TaskInterface
{
protected EvaluatorExecutorInterface $evaluatorExecutor;

/**
* @param EvaluatorExecutorInterface $evaluatorExecutor
*/
public function __construct(EvaluatorExecutorInterface $evaluatorExecutor)
{
$this->evaluatorExecutor = $evaluatorExecutor;
}

public function getId(): string
{
return 'evaluator:run';
}

public function getShortDescription(): string
{
return '';
}

public function getCommands(): array
{
return [
new EvaluateCommand($this->evaluatorExecutor)
];
}

public function getPlaceholders(): array
{
return [];
}

public function getHelp(): ?string
{
return null;
}

public function getVersion(): string
{
return '0.1.0';
}

public function isDeprecated(): bool
{
return false;
}

public function isOptional(): bool
{
return false;
}

public function getSuccessor(): ?string
{
return null;
}

public function getLifecycle(): LifecycleInterface
{
return new Lifecycle(
new InitializedEventData(),
new UpdatedEventData(),
new RemovedEventData(),
);
}

public function getStages(): array
{
return [];
}
}
Loading