UserService::__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\UserRepository;
10
use Carbon\Carbon;
11
12
class UserService
13
{
14
    /** @var UserRepository */
15
    private $repository;
16
17
    /**
18
     * UserService constructor.
19
     */
20
    public function __construct()
21
    {
22
        $this->repository = app(UserRepository::class);
23
    }
24
25
    /**
26
     * @param Carbon $from
27
     *
28
     * @return mixed
29
     */
30
    public function getUserStats($from)
31
    {
32
        $this->repository->clearCriteria();
33
34
        $rawSql = 'DATE_FORMAT(created_at,\'%Y-%m-%d\') as date, count(*) as number';
35
        $this->repository->pushCriteria(new RawSelect($rawSql));
36
        $this->repository->pushCriteria(new Where('created_at', $from->format('Y-m-d h:i:s'), '>'));
37
        $this->repository->pushCriteria(new GroupBy('date'));
38
        $this->repository->pushCriteria(new OrderBy('date', 'desc'));
39
40
        return $this->repository->all();
41
    }
42
43
    public function findByName($username)
44
    {
45
        return $this->repository->findBy('username', $username);
46
    }
47
}
48