Completed
Push — 2.0 ( 29c56f...2f2bc4 )
by Marco
14:43
created

Manager::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 10

Duplication

Lines 15
Ratio 100 %

Importance

Changes 0
Metric Value
dl 15
loc 15
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 10
nc 2
nop 4
1
<?php namespace Comodojo\Extender\Worklog;
2
3
use \Comodojo\Foundation\Base\Configuration;
4
use \Comodojo\Foundation\Base\ConfigurationTrait;
5
use \Comodojo\Foundation\Events\Manager as EventsManager;
6
use \Comodojo\Foundation\Logging\LoggerTrait;
7
use \Comodojo\Foundation\Events\EventsTrait;
8
use \Comodojo\Extender\Components\Database;
9
use \Comodojo\Extender\Traits\EntityManagerTrait;
10
use \Comodojo\Extender\Orm\Entities\Worklog;
11
use \Comodojo\Extender\Events\WorklogEvent;
12
use \Doctrine\ORM\EntityManager;
13
use \Psr\Log\LoggerInterface;
14
use \Exception;
15
16
/**
17
* @package     Comodojo Extender
18
* @author      Marco Giovinazzi <[email protected]>
19
* @license     MIT
20
*
21
* LICENSE:
22
*
23
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
29
* THE SOFTWARE.
30
 */
31
32
class Manager {
33
34
    use ConfigurationTrait;
35
    use LoggerTrait;
36
    use EventsTrait;
37
    use EntityManagerTrait;
38
39
    /**
40
     * Class constructor
41
     *
42
     * @param Configuration $configuration
43
     * @param LoggerInterface $logger
44
     * @param TasksTable $tasks
0 ignored issues
show
Bug introduced by
There is no parameter named $tasks. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
45
     * @param EventsManager $events
46
     * @param EntityManager $em
47
     */
48 View Code Duplication
    public function __construct(
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
49
        Configuration $configuration,
50
        LoggerInterface $logger,
51
        EventsManager $events,
52
        EntityManager $em = null
53
    ) {
54
55
        $this->setConfiguration($configuration);
56
        $this->setLogger($logger);
57
        $this->setEvents($events);
58
59
        $em = is_null($em) ? Database::init($configuration)->getEntityManager() : $em;
60
        $this->setEntityManager($em);
61
62
    }
63
64
    public function count() {
65
66
        $em = $this->getEntityManager();
67
68
        $query = $em->createQuery('SELECT COUNT(w.id) FROM Comodojo\Extender\Orm\Entities\Worklog w');
69
70
        return $query->getSingleScalarResult();
71
72
    }
73
74
    public function get(
75
        array $filter = [],
76
        $limit = 10,
77
        $offset = 0,
78
        $reverse = false
79
    ) {
80
81
        $em = $this->getEntityManager();
82
83
        return $em->getRepository('Comodojo\Extender\Orm\Entities\Worklog')
84
            ->findBy(
85
                $filter,
86
                ['id' => $reverse ? 'DESC' : 'ASC'],
87
                $limit,
88
                $offset
89
            );
90
91
    }
92
93
    public function getOne(array $filter) {
94
95
        $em = $this->getEntityManager();
96
97
        return $em->getRepository('Comodojo\Extender\Orm\Entities\Worklog')
98
            ->findOneBy($filter);
99
    }
100
101
}
102