Completed
Push — master ( 408932...ce7eb5 )
by Dawid
06:58
created

  A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 1
b 0
f 0
1
<?php declare(strict_types=1);
2
require_once __DIR__ . '/../vendor/autoload.php';
3
4
/**
5
 * This example will guide you through working with collection classes.
6
 * You will learn:
7
 * - how to locally map/reduce data
8
 * - how to work with low memory footprint
9
 */
10
11
use Igni\Storage\Driver\Pdo\Connection;
12
use Igni\Storage\Driver\Pdo\ConnectionOptions;
13
use Igni\Storage\Driver\Pdo\Repository;
14
use Igni\Storage\Storable;
15
use Igni\Storage\Id;
16
use Igni\Storage\Id\GenericId;
17
use Igni\Storage\Mapping\Annotation\Entity;
18
use Igni\Storage\Mapping\Annotation\Property;
19
use Igni\Storage\Mapping\MappingStrategy;
20
use Igni\Storage\Mapping\Type;
21
use Igni\Storage\Storage;
22
23
/**
24
 * This is our example entity class - nothing fancy.
25
 * All properties are public to simplify the example.
26
 * All items are taken from tracks table.
27
 * @Entity(source="tracks")
28
 */
29
class Track implements Storable
30
{
31
    /**
32
     * @Property(type="id", name="TrackId", class=GenericId::class)
33
     */
34
    public $id;
35
36
    /**
37
     * @Property(type="string", name="Name")
38
     */
39
    protected $name;
40
41
    public function getId(): Id
42
    {
43
        return $this->id;
44
    }
45
}
46
47
48
$sqlLiteConnection = new Connection(__DIR__ . '/db.db', new ConnectionOptions('sqlite'));
49
$sqlLiteConnection->open();
50
$unitOfWork = new Storage();
51
$unitOfWork->addRepository(new class($sqlLiteConnection, $unitOfWork->getEntityManager()) extends Repository {
0 ignored issues
show
Bug introduced by
$sqlLiteConnection of type Igni\Storage\Driver\Pdo\Connection is incompatible with the type Igni\Storage\EntityManager expected by parameter $entityManager of anonymous//examples/work...le.php$0::__construct(). ( Ignorable by Annotation )

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

51
$unitOfWork->addRepository(new class(/** @scrutinizer ignore-type */ $sqlLiteConnection, $unitOfWork->getEntityManager()) extends Repository {
Loading history...
Unused Code introduced by
The call to anonymous//examples/work...le.php$0::__construct() has too many arguments starting with $unitOfWork->getEntityManager(). ( Ignorable by Annotation )

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

51
$unitOfWork->addRepository(/** @scrutinizer ignore-call */ new class($sqlLiteConnection, $unitOfWork->getEntityManager()) extends Repository {

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
52
    public function getEntityClass(): string
53
    {
54
        return Track::class;
55
    }
56
});
57
58
$track = $unitOfWork->get(Track::class, 1);
59
60
$track->getComposer();// Instance of composer.
0 ignored issues
show
Bug introduced by
The method getComposer() does not exist on Igni\Storage\Storable. It seems like you code against a sub-type of Igni\Storage\Storable such as IgniTest\Fixtures\Track\TrackEntity. ( Ignorable by Annotation )

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

60
$track->/** @scrutinizer ignore-call */ 
61
        getComposer();// Instance of composer.
Loading history...
61
62