1 | <?php |
||
2 | |||
3 | namespace Sunnysideup\SimpleTemplateCaching\Extensions; |
||
4 | |||
5 | use Page; |
||
0 ignored issues
–
show
|
|||
6 | use PageController; |
||
0 ignored issues
–
show
The type
PageController 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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
7 | use PhpParser\Node\Scalar\MagicConst\Dir; |
||
8 | use SilverStripe\CMS\Controllers\ContentController; |
||
9 | use SilverStripe\Control\Director; |
||
10 | use SilverStripe\Control\Middleware\HTTPCacheControlMiddleware; |
||
11 | use SilverStripe\Core\Extension; |
||
12 | use SilverStripe\Security\Security; |
||
13 | use SilverStripe\SiteConfig\SiteConfig; |
||
14 | use SilverStripe\Versioned\Versioned; |
||
15 | |||
16 | /** |
||
17 | * Class \ControllerExtension. |
||
18 | * |
||
19 | * @property PageController|ControllerExtension $owner |
||
20 | */ |
||
21 | class ControllerExtension extends Extension |
||
22 | { |
||
23 | public function onBeforeInit() |
||
24 | { |
||
25 | //make sure that caching is always https |
||
26 | $controller = $this->getOwner(); |
||
27 | /** PageController|ControllerExtension $controller */ |
||
28 | if ($controller instanceof PageController) { |
||
29 | $dataRecord = $controller->data(); |
||
30 | if (empty($dataRecord) || !$dataRecord instanceof Page) { |
||
31 | return $this->returnNoCache(); |
||
0 ignored issues
–
show
Are you sure the usage of
$this->returnNoCache() targeting Sunnysideup\SimpleTempla...ension::returnNoCache() seems to always return null.
This check looks for function or method calls that always return null and whose return value is used. class A
{
function getObject()
{
return null;
}
}
$a = new A();
if ($a->getObject()) {
The method The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes. ![]() |
|||
32 | } |
||
33 | if ($dataRecord->PageCanBeCachedEntirely() !== true) { |
||
34 | return $this->returnNoCache(); |
||
0 ignored issues
–
show
Are you sure the usage of
$this->returnNoCache() targeting Sunnysideup\SimpleTempla...ension::returnNoCache() seems to always return null.
This check looks for function or method calls that always return null and whose return value is used. class A
{
function getObject()
{
return null;
}
}
$a = new A();
if ($a->getObject()) {
The method The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes. ![]() |
|||
35 | } |
||
36 | if (Security::getCurrentUser()) { |
||
37 | return $this->returnNoCache(); |
||
0 ignored issues
–
show
Are you sure the usage of
$this->returnNoCache() targeting Sunnysideup\SimpleTempla...ension::returnNoCache() seems to always return null.
This check looks for function or method calls that always return null and whose return value is used. class A
{
function getObject()
{
return null;
}
}
$a = new A();
if ($a->getObject()) {
The method The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes. ![]() |
|||
38 | } |
||
39 | if (Versioned::get_reading_mode() !== 'Stage.Live') { |
||
40 | return $this->returnNoCache(); |
||
0 ignored issues
–
show
Are you sure the usage of
$this->returnNoCache() targeting Sunnysideup\SimpleTempla...ension::returnNoCache() seems to always return null.
This check looks for function or method calls that always return null and whose return value is used. class A
{
function getObject()
{
return null;
}
}
$a = new A();
if ($a->getObject()) {
The method The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes. ![]() |
|||
41 | } |
||
42 | // avoid test sites being cached |
||
43 | if (Director::isTest()) { |
||
44 | return $this->returnNoCache(); |
||
0 ignored issues
–
show
Are you sure the usage of
$this->returnNoCache() targeting Sunnysideup\SimpleTempla...ension::returnNoCache() seems to always return null.
This check looks for function or method calls that always return null and whose return value is used. class A
{
function getObject()
{
return null;
}
}
$a = new A();
if ($a->getObject()) {
The method The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes. ![]() |
|||
45 | } |
||
46 | |||
47 | // exclude special situations... |
||
48 | $request = $controller->getRequest(); |
||
49 | $action = (string) $request->param('Action'); |
||
50 | if ($action) { |
||
51 | if ($controller->hasMethod('cacheControlExcludedActions')) { |
||
52 | $excludeActions = (array) $controller->cacheControlExcludedActions(); |
||
53 | if (!empty($excludeActions)) { |
||
54 | $action = strtolower((string) $action); |
||
55 | if (in_array($action, $excludeActions)) { |
||
56 | return $this->returnNoCache(); |
||
0 ignored issues
–
show
Are you sure the usage of
$this->returnNoCache() targeting Sunnysideup\SimpleTempla...ension::returnNoCache() seems to always return null.
This check looks for function or method calls that always return null and whose return value is used. class A
{
function getObject()
{
return null;
}
}
$a = new A();
if ($a->getObject()) {
The method The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes. ![]() |
|||
57 | } |
||
58 | } |
||
59 | } |
||
60 | } |
||
61 | if ($request->isAjax()) { |
||
62 | return $this->returnNoCache(); |
||
0 ignored issues
–
show
Are you sure the usage of
$this->returnNoCache() targeting Sunnysideup\SimpleTempla...ension::returnNoCache() seems to always return null.
This check looks for function or method calls that always return null and whose return value is used. class A
{
function getObject()
{
return null;
}
}
$a = new A();
if ($a->getObject()) {
The method The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes. ![]() |
|||
63 | } |
||
64 | if ($request->getVar('flush')) { |
||
65 | return $this->returnNoCache(); |
||
0 ignored issues
–
show
Are you sure the usage of
$this->returnNoCache() targeting Sunnysideup\SimpleTempla...ension::returnNoCache() seems to always return null.
This check looks for function or method calls that always return null and whose return value is used. class A
{
function getObject()
{
return null;
}
}
$a = new A();
if ($a->getObject()) {
The method The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes. ![]() |
|||
66 | } |
||
67 | if ($request->postVars()) { |
||
68 | return $this->returnNoCache(); |
||
0 ignored issues
–
show
Are you sure the usage of
$this->returnNoCache() targeting Sunnysideup\SimpleTempla...ension::returnNoCache() seems to always return null.
This check looks for function or method calls that always return null and whose return value is used. class A
{
function getObject()
{
return null;
}
}
$a = new A();
if ($a->getObject()) {
The method The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes. ![]() |
|||
69 | } |
||
70 | if ($request->isGET() !== true) { |
||
71 | return $this->returnNoCache(); |
||
0 ignored issues
–
show
Are you sure the usage of
$this->returnNoCache() targeting Sunnysideup\SimpleTempla...ension::returnNoCache() seems to always return null.
This check looks for function or method calls that always return null and whose return value is used. class A
{
function getObject()
{
return null;
}
}
$a = new A();
if ($a->getObject()) {
The method The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes. ![]() |
|||
72 | } |
||
73 | if ($controller->hasMethod('canCachePage')) { |
||
74 | $canCachePage = $controller->canCachePage(); |
||
75 | if ($canCachePage !== true) { |
||
76 | return $this->returnNoCache(); |
||
0 ignored issues
–
show
Are you sure the usage of
$this->returnNoCache() targeting Sunnysideup\SimpleTempla...ension::returnNoCache() seems to always return null.
This check looks for function or method calls that always return null and whose return value is used. class A
{
function getObject()
{
return null;
}
}
$a = new A();
if ($a->getObject()) {
The method The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes. ![]() |
|||
77 | } |
||
78 | } |
||
79 | $cacheTime = $dataRecord->PageCanBeCachedEntirelyDuration(); |
||
80 | if ($cacheTime > 0) { |
||
81 | return HTTPCacheControlMiddleware::singleton() |
||
82 | ->enableCache() |
||
83 | ->setMaxAge($cacheTime) |
||
84 | ->publicCache(true) |
||
85 | ; |
||
86 | } |
||
87 | } |
||
88 | |||
89 | return null; |
||
90 | } |
||
91 | |||
92 | protected function returnNoCache() |
||
93 | { |
||
94 | HTTPCacheControlMiddleware::singleton() |
||
95 | ->disableCache() |
||
96 | ; |
||
97 | return null; |
||
98 | } |
||
99 | } |
||
100 |
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:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths