Model::__call()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 2
crap 2
1
<?php
2
3
/**
4
 * This file is part of the Grido (https://github.com/o5/grido)
5
 *
6
 * Copyright (c) 2011 Petr Bugyík (http://petr.bugyik.cz)
7
 *
8
 * For the full copyright and license information, please view
9
 * the file LICENSE.md that was distributed with this source code.
10
 */
11
12
namespace Grido\DataSources;
13
14
use Grido\Exception;
15
16
/**
17
 * Model of data source.
18
 *
19
 * @package     Grido
20
 * @subpackage  DataSources
21
 * @author      Petr Bugyík
22
 *
23
 * @property-read IDataSource $dataSource
24
 */
25
class Model
26 1
{
27
    use \Nette\SmartObject;
28
29
    /** @var array */
30
    public $callback = [];
31
32
    /** @var IDataSource */
33
    protected $dataSource;
34
35
    /**
36
     * @param mixed $model
37
     * @throws Exception
38
     */
39 1
    public function __construct($model)
40 1
    {
41 1
        if ($model instanceof \Dibi\Fluent) {
0 ignored issues
show
Bug introduced by
The class Dibi\Fluent does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
42 1
            $dataSource = new DibiFluent($model);
43 1
        } elseif ($model instanceof \Nette\Database\Table\Selection) {
0 ignored issues
show
Bug introduced by
The class Nette\Database\Table\Selection does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
44 1
            $dataSource = new NetteDatabase($model);
45 1
        } elseif ($model instanceof \Doctrine\ORM\QueryBuilder) {
0 ignored issues
show
Bug introduced by
The class Doctrine\ORM\QueryBuilder does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
46 1
            $dataSource = new Doctrine($model);
47 1
        } elseif (is_array($model)) {
48 1
            $dataSource = new ArraySource($model);
49 1
        } elseif ($model instanceof IDataSource) {
50 1
            $dataSource = $model;
51
        } else {
52
            throw new Exception('Model must implement \Grido\DataSources\IDataSource.');
53 1
        }
54 1
55
        $this->dataSource = $dataSource;
56
    }
57
58
    /**
59
     * @return IDataSource
60
     */
61 1
    public function getDataSource()
62
    {
63
        return $this->dataSource;
64
    }
65
66 1
    public function __call($method, $args)
67 1
    {
68 1
        return isset($this->callback[$method])
69
            ? call_user_func_array($this->callback[$method], [$this->dataSource, $args])
70
            : call_user_func_array([$this->dataSource, $method], $args);
71 1
    }
72
}
73