AsgardCms /
Page
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php namespace Modules\Page\Http\Controllers; |
||
| 2 | |||
| 3 | use Illuminate\Contracts\Foundation\Application; |
||
| 4 | use Modules\Core\Http\Controllers\BasePublicController; |
||
| 5 | use Modules\Page\Repositories\PageRepository; |
||
| 6 | |||
| 7 | class PublicController extends BasePublicController |
||
| 8 | { |
||
| 9 | /** |
||
| 10 | * @var PageRepository |
||
| 11 | */ |
||
| 12 | private $page; |
||
| 13 | /** |
||
| 14 | * @var Application |
||
| 15 | */ |
||
| 16 | private $app; |
||
| 17 | |||
| 18 | public function __construct(PageRepository $page, Application $app) |
||
| 19 | { |
||
| 20 | parent::__construct(); |
||
| 21 | $this->page = $page; |
||
| 22 | $this->app = $app; |
||
| 23 | } |
||
| 24 | |||
| 25 | /** |
||
| 26 | * @param $slug |
||
| 27 | * @return \Illuminate\View\View |
||
| 28 | */ |
||
| 29 | public function uri($slug) |
||
| 30 | { |
||
| 31 | $page = $this->page->findBySlugInLocale($slug, $this->locale); |
||
| 32 | |||
| 33 | $this->throw404IfNotFound($page); |
||
| 34 | |||
| 35 | $template = $this->getTemplateForPage($page); |
||
| 36 | |||
| 37 | return view($template, compact('page')); |
||
|
0 ignored issues
–
show
Bug
Compatibility
introduced
by
Loading history...
|
|||
| 38 | } |
||
| 39 | |||
| 40 | /** |
||
| 41 | * @return \Illuminate\View\View |
||
| 42 | */ |
||
| 43 | public function homepage() |
||
| 44 | { |
||
| 45 | $page = $this->page->findHomepage(); |
||
| 46 | |||
| 47 | $this->throw404IfNotFound($page); |
||
| 48 | |||
| 49 | $template = $this->getTemplateForPage($page); |
||
| 50 | |||
| 51 | return view($template, compact('page')); |
||
|
0 ignored issues
–
show
The expression
view($template, compact('page')); of type Illuminate\View\View|Ill...\Contracts\View\Factory adds the type Illuminate\Contracts\View\Factory to the return on line 51 which is incompatible with the return type documented by Modules\Page\Http\Contro...licController::homepage of type Illuminate\View\View.
Loading history...
|
|||
| 52 | } |
||
| 53 | |||
| 54 | /** |
||
| 55 | * Return the template for the given page |
||
| 56 | * or the default template if none found |
||
| 57 | * @param $page |
||
| 58 | * @return string |
||
| 59 | */ |
||
| 60 | private function getTemplateForPage($page) |
||
| 61 | { |
||
| 62 | return (view()->exists($page->template)) ? $page->template : 'default'; |
||
|
0 ignored issues
–
show
The method
exists does only exist in Illuminate\Contracts\View\Factory, but not in Illuminate\View\View.
It seems like the method you are trying to call exists only in some of the possible types. Let’s take a look at an example: class A
{
public function foo() { }
}
class B extends A
{
public function bar() { }
}
/**
* @param A|B $x
*/
function someFunction($x)
{
$x->foo(); // This call is fine as the method exists in A and B.
$x->bar(); // This method only exists in B and might cause an error.
}
Available Fixes
Loading history...
|
|||
| 63 | } |
||
| 64 | |||
| 65 | /** |
||
| 66 | * Throw a 404 error page if the given page is not found |
||
| 67 | * @param $page |
||
| 68 | */ |
||
| 69 | private function throw404IfNotFound($page) |
||
| 70 | { |
||
| 71 | if (is_null($page)) { |
||
| 72 | $this->app->abort('404'); |
||
| 73 | } |
||
| 74 | } |
||
| 75 | } |
||
| 76 |