Completed
Push — master ( cf2713...aee5ae )
by Sherif
02:07
created

ReportService   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 0
loc 48
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getReport() 0 18 4
1
<?php namespace App\Modules\Reporting\Services;
2
3
use App\Modules\Core\BaseClasses\BaseService;
4
use App\Modules\Reporting\Repositories\ReportRepository;
5
use App\Modules\Users\Services\UserService;
6
7
class ReportService extends BaseService
8
{
9
    /**
10
     * @var UserService
11
     */
12
    protected $userService;
13
14
    /**
15
     * Init new object.
16
     *
17
     * @param   ReportRepository $repo
18
     * @return  void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
19
     */
20
    public function __construct(ReportRepository $repo, UserService $userService)
21
    {
22
        $this->userService = $userService;
23
        parent::__construct($repo);
24
    }
25
26
    /**
27
     * Render the given report db view based on the given
28
     * condition.
29
     *
30
     * @param  string  $reportName
31
     * @param  array   $conditions
32
     * @param  integer $perPage
33
     * @param  boolean $skipPermission
34
     * @return object
35
     */
36
    public function getReport($reportName, $conditions = [], $perPage = 0, $skipPermission = false)
37
    {
38
        /**
39
         * Fetch the report from db.
40
         */
41
        $report = $this->repo->first(['report_name' => $reportName]);
42
43
        /**
44
         * Check report existance and permission.
45
         */
46
        if (! $report) {
47
            \ErrorHandler::notFound('report');
48
        } elseif (! $skipPermission && ! $this->userService->can($report->view_name, 'report')) {
49
            \ErrorHandler::noPermissions();
50
        }
51
52
       return $this->repo->renderReport($report, $conditions, $perPage);
53
    }
54
}
55