SnapshotController::index()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
3
use App\Exceptions\RepositoryException;
4
use App\Repositories\SnapshotDetailsRepository;
5
use App\Repositories\SnapshotRepository;
6
use Input;
7
use Response;
8
9
class SnapshotController extends \Controller {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
10
	
11
	protected $repository;
12
13
	public function __construct(SnapshotRepository $repository)
14
	{
15
		$this->repository = $repository;
16
	}
17
18
	public function index()
19
	{
20
		$snapshots = $this->repository->all();
21
		return Response::json( $this->repository->APIFormat($snapshots), 200);
22
	}
23
24
	public function store()
25
	{		
26
		$snapshot = $this->repository->store( Input::all() );
27
		return Response::json( ['id' => $snapshot->id], 200);
0 ignored issues
show
Documentation introduced by
The property id does not exist on object<App\Models\CashSnapshots>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read 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.");
        }
    }

}

If the property has read access only, you can use the @property-read 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...
28
	}
29
30
	public function show($id)
31
	{
32
		$snapshot = $this->repository->get($id);
33
		return Response::json($this->repository->APIFormat($snapshot), 200);
34
	}
35
36
	public function getCurrent()
37
	{
38
		$snapshot = $this->repository->current();
39
		return Response::json($this->repository->APIFormat($snapshot), 200);
40
	}
41
42
}
43