|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* This file is part of the Superdesk Web Publisher Core Bundle. |
|
7
|
|
|
* |
|
8
|
|
|
* Copyright 2018 Sourcefabric z.ú. and contributors. |
|
9
|
|
|
* |
|
10
|
|
|
* For the full copyright and license information, please see the |
|
11
|
|
|
* AUTHORS and LICENSE files distributed with this source code. |
|
12
|
|
|
* |
|
13
|
|
|
* @copyright 2018 Sourcefabric z.ú |
|
14
|
|
|
* @license http://www.superdesk.org/license |
|
15
|
|
|
*/ |
|
16
|
|
|
|
|
17
|
|
|
namespace SWP\Bundle\CoreBundle\Rule\Processor; |
|
18
|
|
|
|
|
19
|
|
|
use SWP\Bundle\CoreBundle\Repository\RuleRepositoryInterface; |
|
20
|
|
|
use SWP\Component\Rule\Applicator\RuleApplicatorInterface; |
|
21
|
|
|
use SWP\Component\Rule\Evaluator\RuleEvaluatorInterface; |
|
22
|
|
|
use SWP\Component\Rule\Model\RuleSubjectInterface; |
|
23
|
|
|
use SWP\Component\Rule\Processor\RuleProcessorInterface; |
|
24
|
|
|
|
|
25
|
|
View Code Duplication |
final class OrganizationRuleProcessor implements RuleProcessorInterface |
|
|
|
|
|
|
26
|
|
|
{ |
|
27
|
|
|
/** |
|
28
|
|
|
* @var RuleRepositoryInterface |
|
29
|
|
|
*/ |
|
30
|
|
|
private $ruleRepository; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @var RuleEvaluatorInterface |
|
34
|
|
|
*/ |
|
35
|
|
|
private $ruleEvaluator; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @var RuleApplicatorInterface |
|
39
|
|
|
*/ |
|
40
|
|
|
private $ruleApplicator; |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* RuleProcessor constructor. |
|
44
|
|
|
* |
|
45
|
|
|
* @param RuleRepositoryInterface $ruleRepository |
|
46
|
|
|
* @param RuleEvaluatorInterface $ruleEvaluator |
|
47
|
|
|
* @param RuleApplicatorInterface $ruleApplicator |
|
48
|
|
|
*/ |
|
49
|
|
|
public function __construct( |
|
50
|
|
|
RuleRepositoryInterface $ruleRepository, |
|
51
|
|
|
RuleEvaluatorInterface $ruleEvaluator, |
|
52
|
|
|
RuleApplicatorInterface $ruleApplicator |
|
53
|
|
|
) { |
|
54
|
|
|
$this->ruleRepository = $ruleRepository; |
|
55
|
|
|
$this->ruleEvaluator = $ruleEvaluator; |
|
56
|
|
|
$this->ruleApplicator = $ruleApplicator; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* {@inheritdoc} |
|
61
|
|
|
*/ |
|
62
|
|
|
public function process(RuleSubjectInterface $subject) |
|
63
|
|
|
{ |
|
64
|
|
|
$rules = $this->ruleRepository->findOrganizationRules(); |
|
65
|
|
|
|
|
66
|
|
|
foreach ($rules as $rule) { |
|
67
|
|
|
if ($this->ruleEvaluator->evaluate($rule, $subject)) { |
|
68
|
|
|
$this->ruleApplicator->apply($rule, $subject); |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.