SolutionService::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
namespace App\Services;
4
5
use App\Repositories\Criteria\GroupBy;
6
use App\Repositories\Criteria\OrderBy;
7
use App\Repositories\Criteria\RawSelect;
8
use App\Repositories\Criteria\Where;
9
use App\Repositories\SolutionRepository;
10
use Carbon\Carbon;
11
12
class SolutionService
13
{
14
    /** @var SolutionRepository */
15
    private $repository;
16
17
    /**
18
     * SolutionService constructor.
19
     */
20
    public function __construct()
21
    {
22
        $this->repository = app(SolutionRepository::class);
23
    }
24
25
    public function find($id)
26
    {
27
        return $this->repository->find($id);
28
    }
29
30
    /**
31
     * @param Carbon $from
32
     *
33
     * @return mixed
34
     */
35
    public function getSubmissionStats($from)
36
    {
37
        $this->repository->clearCriteria();
38
39
        $rawSql = 'DATE_FORMAT(created_at,\'%Y-%m-%d\') as date, count(*) as number';
40
        $this->repository->pushCriteria(new RawSelect($rawSql));
41
        $this->repository->pushCriteria(new Where('created_at', $from->format('Y-m-d h:i:s'), '>'));
42
        $this->repository->pushCriteria(new GroupBy('date'));
43
        $this->repository->pushCriteria(new OrderBy('date', 'desc'));
44
45
        return $this->repository->all();
46
    }
47
}
48