GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

DoctrinePlaceholderContext::setPlaceholderBag()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
declare(strict_types = 1);
3
4
namespace espend\Behat\PlaceholderExtension\Context;
5
6
use Behat\Behat\Context\Context;
7
use Behat\Symfony2Extension\Context\KernelDictionary;
8
use espend\Behat\PlaceholderExtension\PlaceholderBagInterface;
9
use espend\Behat\PlaceholderExtension\Utils\PlaceholderUtil;
10
use PHPUnit\Framework\Assert as Assertions;
11
use Symfony\Component\PropertyAccess\Exception\AccessException;
12
use Symfony\Component\PropertyAccess\PropertyAccess;
13
14
/**
15
 * @author Daniel Espendiller <[email protected]>
16
 */
17
class DoctrinePlaceholderContext implements Context, PlaceholderBagAwareContextInterface
18
{
19
    use KernelDictionary;
20
21
    /**
22
     * @var PlaceholderBagInterface
23
     */
24
    private $placeholderBag;
25
26
    /**
27
     * @param string $placeholder
28
     * @param string $model Entity, Repository or class name
29
     * @param string $leftOperator filter property
30
     * @param string $rightOperator filter property value
31
     * @param string $property Symfony PropertyAccessor syntax eg "foo.bar" "foo[bar]"
32
     * @Given /^set placeholder "([^"]*)" of "([^"]*)" on Doctrine model "([^"]*)" with "([^"]*)" equals "([^"]*)"$/
33
     */
34 5
    public function setPlaceholderOfPropertyOnDoctrineModelWithCriteriaAndProperty(
35
        string $placeholder,
36
        string $property,
37
        string $model,
38
        string $leftOperator,
39
        string $rightOperator
40
    ) {
41 5
        PlaceholderUtil::isValidPlaceholderOrThrowException($placeholder);
42
43 3
        $manager = $this->getContainer()->get('doctrine')->getManagerForClass($model);
44 3
        Assertions::assertNotNull($manager, 'No valid Doctrine manager found for ' . $model);
45
46 3
        $object = $manager->getRepository($model)->findOneBy([$leftOperator => $rightOperator]);
47
48 3
        Assertions::assertNotNull(
49 3
            $object,
50 3
            sprintf('No valid model found "%s" "%s", "%s"', $model, $leftOperator . '=' . $rightOperator , $property)
51
        );
52
53
        try {
54 2
            $value = PropertyAccess::createPropertyAccessor()->getValue($object, $property);
55 1
        } catch (AccessException $e) {
56 1
            Assertions::fail('Invalid value not found: ' . $e->getMessage());
57
            return;
58
        }
59
60 1
        $this->placeholderBag->add($placeholder, (string)$value);
61 1
    }
62
63
    /**
64
     * {@inheritdoc}
65
     */
66 4
    public function setPlaceholderBag(PlaceholderBagInterface $placeholderBag)
67
    {
68 4
        $this->placeholderBag = $placeholderBag;
69 4
    }
70
}
71