Manager::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 4
dl 0
loc 13
rs 10
c 0
b 0
f 0
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
The type Comodojo\Extender\Worklog\TasksTable was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
45
     * @param EventsManager $events
46
     * @param EntityManager $em
47
     */
48
    public function __construct(
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