Completed
Push — apply-code-style ( 1a43bf...37cc85 )
by
unknown
45:48
created

ContentTranslationEvaluator::evaluate()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 2
dl 0
loc 11
rs 9.9
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
5
 * @license For full copyright and license information view LICENSE file distributed with this source code.
6
 */
7
declare(strict_types=1);
8
9
namespace eZ\Publish\Core\Limitation\LanguageLimitation;
10
11
use eZ\Publish\API\Repository\Values\User\Limitation;
12
use eZ\Publish\Core\Limitation\LanguageLimitationType;
13
use eZ\Publish\SPI\Limitation\Target;
14
15
/**
16
 * @internal for internal use by LanguageLimitation
17
 */
18
final class ContentTranslationEvaluator implements VersionTargetEvaluator
19
{
20
    public function accept(Target\Version $targetVersion): bool
21
    {
22
        return !empty($targetVersion->allLanguageCodesList);
23
    }
24
25
    /**
26
     * Allow access if any of the given language codes for translations matches any of the limitation values.
27
     */
28
    public function evaluate(Target\Version $targetVersion, Limitation $limitationValue): ?bool
29
    {
30
        $matchingTranslations = array_intersect(
31
            $targetVersion->allLanguageCodesList,
32
            $limitationValue->limitationValues
33
        );
34
35
        return empty($matchingTranslations)
36
            ? LanguageLimitationType::ACCESS_DENIED
37
            : LanguageLimitationType::ACCESS_GRANTED;
38
    }
39
}
40