Completed
Push — master ( 8c51b1...9340a0 )
by Paweł
07:46
created

OrganizationRuleProcessor   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 48
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 48
loc 48
c 0
b 0
f 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 9 9 1
A process() 10 10 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

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.

Loading history...
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