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.
Passed
Push — master ( 8846c9...67b391 )
by 12345
39s
created

DoctrinePlaceholderContext   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 7
dl 0
loc 52
ccs 0
cts 26
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
B iSetAPlaceholderOnDoctrineModelWithCriteriaAndProperty() 0 27 2
A setPlaceholderBag() 0 4 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 PHPUnit\Framework\Assert as Assertions;
10
use Symfony\Component\PropertyAccess\Exception\AccessException;
11
use Symfony\Component\PropertyAccess\PropertyAccess;
12
13
/**
14
 * @author Daniel Espendiller <[email protected]>
15
 */
16
class DoctrinePlaceholderContext implements Context, PlaceholderBagAwareContext
17
{
18
    use KernelDictionary;
19
20
    /**
21
     * @var PlaceholderBagInterface
22
     */
23
    private $placeholderBag;
24
25
    /**
26
     * @param string $placeholder
27
     * @param string $model Entity, Repository or class name
28
     * @param string $criteria properties to filter on eg "id=foobar" parse_str supported
29
     * @param string $property Symfony PropertyAccessor syntax eg "foo.bar" "foo[bar]"
30
     * @Given /^I set a placeholder "([^"]*)" on Doctrine model "([^"]*)" with "([^"]*)" and "([^"]*)"$/
31
     */
32
    public function iSetAPlaceholderOnDoctrineModelWithCriteriaAndProperty(
33
        string $placeholder,
34
        string $model,
35
        string $criteria,
36
        string $property
37
    ) {
38
        $manager = $this->getContainer()->get('doctrine')->getManagerForClass($model);
39
        Assertions::assertNotNull($manager, 'No valid Doctrine manager found for ' . $model);
40
41
        parse_str($criteria, $find);
42
43
        $object = $manager->getRepository($model)->findOneBy($find);
44
45
        Assertions::assertNotNull(
46
            $object,
47
            sprintf('No valid model found "%s" "%s", "%s"', $model, $criteria, $property)
48
        );
49
50
        try {
51
            $value = PropertyAccess::createPropertyAccessor()->getValue($object, $property);
52
        } catch (AccessException $e) {
53
            Assertions::fail('Invalid value not found: ' . $e->getMessage());
54
            return;
55
        }
56
57
        $this->placeholderBag->add($placeholder, (string)$value);
58
    }
59
60
    /**
61
     * {@inheritdoc}
62
     */
63
    public function setPlaceholderBag(PlaceholderBagInterface $placeholderBag)
64
    {
65
        $this->placeholderBag = $placeholderBag;
66
    }
67
}
68