Test Setup Failed
Push — develop ( b46587...bd8dda )
by Craig
07:01
created

DatastoreController::___tests()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 23
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 6
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 23
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A DatastoreController::articleByAuthor() 0 2 1
A DatastoreController::childPage() 0 2 1
1
<?php
2
3
namespace Phpsa\Datastore\Http\Controllers;
4
5
use App\Http\Controllers\Controller;
0 ignored issues
show
Bug introduced by
The type App\Http\Controllers\Controller was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use Phpsa\Datastore\Datastore;
7
use Phpsa\Datastore\Asset;
8
use Phpsa\Datastore\Helpers;
9
use Phpsa\Datastore\DatastoreException;
10
use Phpsa\Datastore\Repositories\DatastoreRepository;
11
12
use Phpsa\Datastore\Models\Datastore as DatastoreModel;
13
use Phpsa\Datastore\Models\DatastorePages;
14
15
Class DatastoreController extends Controller {
16
17
	/**
18
	 * @var DatastoreRepository
19
	 */
20
    protected $datastoreRepository;
21
22
    /**
23
     * UserController constructor.
24
     *
25
     * @param DatastoreRepository $datastoreRepository
26
	 * @todo get rid of these datastoreRepository and make use of the mode only
27
     */
28
    public function __construct(DatastoreRepository $datastoreRepository)
29
    {
30
        $this->datastoreRepository = $datastoreRepository;
31
	}
32
33
	/**
34
	 * Checks if the current user can manage else set status column
35
	 * this allows us to filter out unpublished items to public but allow admins to
36
	 * view unpublished items
37
	 *
38
	 * @param string $permission
39
	 *
40
	 * @return string|null
41
	 */
42
	protected function canViewAll($status = 'published') :string
43
	{
44
		$user = auth()->user();
45
		return $user && $user->can('manage datastore') ? null : $status;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $user && $user->c...tore') ? null : $status could return the type null which is incompatible with the type-hinted return string. Consider adding an additional type-check to rule them out.
Loading history...
46
	}
47
48
	/**
49
	 * gets page based on the slug
50
	 *
51
	 * @param string $slug
52
	 *
53
	 * @return DatastorePages
54
	 */
55
	protected function getPageBySlug($slug){
56
		$page = DatastorePages::where('slug', $slug)->first();
57
		if(!$page){
58
			abort(404);
59
		}
60
61
		$datastore = $page->datastore;
62
		$user = auth()->user();
63
64
		if(!$datastore->statusIsActive() && (!$user || !$user->can('manage datastore'))) {
0 ignored issues
show
Bug introduced by
The method statusIsActive() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

64
		if(!$datastore->/** @scrutinizer ignore-call */ statusIsActive() && (!$user || !$user->can('manage datastore'))) {

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
65
			abort(404);
66
		}
67
		return $page;
68
	}
69
70
	/**
71
	 * Gets the page view based off of the slug passed in
72
	 *
73
	 * @param string $slug
74
	 *
75
	 * @return \Illuminate\View\View|\Illuminate\Contracts\View\Factory
76
	 */
77
	public function page($slug){
78
79
		$page = $this->getPageBySlug($slug);
80
81
		$acceptedAssets = $page->datastore->accept ? $this->datastoreRepository->paginateAccepted($page->asset, $this->canViewAll(Helpers::getStatusEquals($page->datastore->accept))) : false;
0 ignored issues
show
Bug Best Practice introduced by
The property accept does not exist on Phpsa\Datastore\Datastore. Since you implemented __get, consider adding a @property annotation.
Loading history...
82
83
		return view($page->datastore->getViewName())
0 ignored issues
show
Bug introduced by
The method getViewName() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

83
		return view($page->datastore->/** @scrutinizer ignore-call */ getViewName())

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
84
		->withDatastore($page->datastore)
85
		->withChildren($page->datastore->children())
86
		->withAccepted($acceptedAssets)
87
		->withPage($page);
88
89
	}
90
91
	public function childPage($parent_slug, $slug){
92
		return $this->page($slug);
93
	}
94
95
	public function articleByAuthor($author_id, $slug){
96
		$this->datastoreRepository->paginateSearchProp('author', $author_id, Phpsa\Datastore\Ams\Article\ItemAsset::class, $this->canViewAll('published'));
0 ignored issues
show
Bug introduced by
The type Phpsa\Datastore\Http\Con...e\Ams\Article\ItemAsset was not found. Did you mean Phpsa\Datastore\Ams\Article\ItemAsset? If so, make sure to prefix the type with \.
Loading history...
97
	}
98
99
}