UserService   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 3
Bugs 1 Features 0
Metric Value
eloc 11
c 3
b 1
f 0
dl 0
loc 34
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getUserStats() 0 11 1
A findByName() 0 3 1
A __construct() 0 3 1
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