EventPassChart::mount()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 2
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 4
rs 10
1
<?php
2
3
namespace Adminetic\Website\Http\Livewire\Admin\Charts\Event;
4
5
use Adminetic\Website\Models\Admin\Event;
0 ignored issues
show
Bug introduced by
The type Adminetic\Website\Models\Admin\Event 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...
6
use Adminetic\Website\Models\Admin\Pass;
0 ignored issues
show
Bug introduced by
The type Adminetic\Website\Models\Admin\Pass 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...
7
use Adminetic\Website\Services\Statistic;
8
use Illuminate\Support\Facades\Cache;
9
use Livewire\Component;
10
11
class EventPassChart extends Component
12
{
13
    public $event;
14
    public $passes;
15
    public $chart = 1; // 1 = Area | 2 = Bar
16
    public $per = 1; // 1 = Day | 2 = Month
17
18
    protected $listeners = ['initialize_event_pass_chart' => 'initializeEventPassChart'];
19
20
    public function mount($event = null)
21
    {
22
        $this->event = $event;
23
        $this->passes = ! is_null($event) ? $event->passes : Pass::orderBy('position')->get();
24
    }
25
26
    public function initializeEventPassChart()
27
    {
28
        $passes = $this->passes;
29
        $total_pass_limit = ! is_null($this->event) ? $this->event->total_limit : (Cache::get('events', Event::orderBy('position')->get()))->reduce(function (int $total, $event) {
30
            return $total + $event->total_limit;
31
        }, 0);
32
        $total_registered_pass = ! is_null($this->event) ? $this->event->passes->count() : Pass::count();
33
        $total_remaining_pass = $total_pass_limit - $total_registered_pass;
34
        $this->dispatchBrowserEvent('initializeEventPassChart', [
35
            'passRegisterPerDay' => (new Statistic)->passRegisterPerDay($passes),
36
            'total_pass' => $total_pass_limit,
37
            'total_registered_pass' => $total_registered_pass,
38
            'total_remaining_pass' => $total_remaining_pass,
39
        ]);
40
    }
41
42
    public function render()
43
    {
44
        return view('website::livewire.admin.charts.event.event-pass-chart');
45
    }
46
}
47