DoctrineHelperTrait::findOneByGlobalId()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 1
c 2
b 0
f 0
dl 0
loc 3
ccs 0
cts 3
cp 0
rs 10
cc 1
nc 1
nop 1
crap 2
1
<?php
2
/*******************************************************************************
3
 *  This file is part of the GraphQL Bundle package.
4
 *
5
 *  (c) YnloUltratech <[email protected]>
6
 *
7
 *  For the full copyright and license information, please view the LICENSE
8
 *  file that was distributed with this source code.
9
 ******************************************************************************/
10
11
namespace Ynlo\GraphQLBundle\Test\Helper;
12
13
use Doctrine\Bundle\DoctrineBundle\Registry;
14
use Doctrine\Common\Persistence\ObjectRepository;
15
use Doctrine\ORM\EntityRepository;
16
use Symfony\Bundle\FrameworkBundle\Client;
17
use Ynlo\GraphQLBundle\Model\NodeInterface;
18
use Ynlo\GraphQLBundle\Util\IDEncoder;
19
20
/**
21
 * @method Client getClient()
22
 *
23
 * @deprecated in favor of Behat tests
24
 */
25
trait DoctrineHelperTrait
26
{
27
    public static function getDoctrine(): Registry
28
    {
29
        return static::getClient()->getKernel()->getContainer()->get('doctrine');
0 ignored issues
show
Bug Best Practice introduced by
The method Ynlo\GraphQLBundle\Test\...elperTrait::getClient() is not static, but was called statically. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

29
        return static::/** @scrutinizer ignore-call */ getClient()->getKernel()->getContainer()->get('doctrine');
Loading history...
Bug Best Practice introduced by
The expression return static::getClient...iner()->get('doctrine') could return the type null which is incompatible with the type-hinted return Doctrine\Bundle\DoctrineBundle\Registry. Consider adding an additional type-check to rule them out.
Loading history...
30
    }
31
32
    /**
33
     * @param string $class
34
     *
35
     * @return ObjectRepository|EntityRepository
36
     */
37
    public static function getRepository(string $class): ObjectRepository
38
    {
39
        return static::getDoctrine()->getRepository($class);
0 ignored issues
show
Bug Best Practice introduced by
The expression return static::getDoctri...->getRepository($class) returns the type Doctrine\Persistence\ObjectRepository which includes types incompatible with the type-hinted return Doctrine\Common\Persistence\ObjectRepository.
Loading history...
40
    }
41
42
    /**
43
     * Find a database record from global id
44
     *
45
     * findOneByGlobalId('VXNlcjox') => object
46
     *
47
     * @param mixed $id
48
     *
49
     * @return NodeInterface
50
     */
51
    public static function findOneByGlobalId($id)
52
    {
53
        return IDEncoder::decode($id);
54
    }
55
}
56