Completed
Push — master ( 542498...7eecb4 )
by Kirill
03:23
created

AchievementsController   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5
Metric Value
wmc 1
lcom 0
cbo 5
dl 0
loc 27
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A index() 0 21 1
1
<?php
2
/**
3
 * This file is part of GitterBot package.
4
 *
5
 * @author Serafim <[email protected]>
6
 * @date 14.10.2015 11:21
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
namespace App\Http\Controllers\Api;
12
13
use App\Achieve;
14
use Illuminate\Support\Collection;
15
use App\Http\Controllers\Controller;
16
use App\Subscribers\AchieveSubscriber;
17
use App\Gitter\Achieve\AbstractAchieve;
18
19
/**
20
 * Class AchievementsController
21
 * @package App\Http\Controllers
22
 */
23
class AchievementsController extends Controller
24
{
25
    /**
26
     * @return \Illuminate\Database\Eloquent\Collection|static[]
27
     */
28
    public function index()
29
    {
30
        return \Cache::remember('achievements', 10, function () {
31
            $achieveStorage = [];
32
33
            (new Achieve())
34
                ->selectRaw('name, count(user_id) as count')
35
                ->groupBy('name')
36
                ->get()
37
                ->each(function ($item) use (&$achieveStorage) {
38
                    $achieveStorage[$item->name] = $item->count;
39
                });
40
41
            return (new AchieveSubscriber())
42
                ->toCollection()
43
                ->each(function (AbstractAchieve $achieve) use ($achieveStorage) {
44
                    $achieve->users = $achieveStorage[$achieve->name] ?? 0;
0 ignored issues
show
Documentation introduced by
The property users does not exist on object<App\Gitter\Achieve\AbstractAchieve>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
45
                })
46
                ->toArray();
47
        });
48
    }
49
}