This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace SG\Cache; |
||
4 | |||
5 | use SG\SemanticDataComparator; |
||
6 | use SG\PropertyRegistrationHelper; |
||
7 | |||
8 | use SMW\Store; |
||
9 | use SMW\SemanticData; |
||
10 | use SMW\DIWikiPage; |
||
11 | use SMW\DIProperty; |
||
12 | |||
13 | use Lingo\LingoParser; |
||
14 | |||
15 | use MediaWiki\Linker\LinkTarget; |
||
16 | |||
17 | /** |
||
18 | * @ingroup SG |
||
19 | * @ingroup SemanticGlossary |
||
20 | * |
||
21 | * @license GNU GPL v2+ |
||
22 | * @since 1.0 |
||
23 | * |
||
24 | * @author Stephan Gambke |
||
25 | * @author mwjames |
||
26 | */ |
||
27 | class CacheInvalidator { |
||
28 | |||
29 | /** |
||
30 | * @var CacheInvalidator |
||
31 | */ |
||
32 | private static $instance = null; |
||
33 | |||
34 | /** |
||
35 | * @var GlossaryCache |
||
36 | */ |
||
37 | private $cache = null; |
||
38 | |||
39 | /** |
||
40 | * @since 1.0 |
||
41 | * |
||
42 | * @return CacheInvalidator |
||
43 | */ |
||
44 | 4 | public static function getInstance() { |
|
45 | |||
46 | 4 | if ( self::$instance === null ) { |
|
47 | |||
48 | 1 | $instance = new self(); |
|
49 | 1 | $instance->setCache( new GlossaryCache() ); |
|
50 | |||
51 | 1 | self::$instance = $instance; |
|
52 | } |
||
53 | |||
54 | 4 | return self::$instance; |
|
55 | } |
||
56 | |||
57 | /** |
||
58 | * @since 1.0 |
||
59 | */ |
||
60 | 1 | public static function clear() { |
|
61 | 1 | self::$instance = null; |
|
62 | 1 | } |
|
63 | |||
64 | /** |
||
65 | * @since 1.0 |
||
66 | * |
||
67 | * @param GlossaryCache $glossaryCache |
||
68 | */ |
||
69 | 7 | public function setCache( GlossaryCache $glossaryCache ) { |
|
70 | 7 | $this->glossaryCache = $glossaryCache; |
|
0 ignored issues
–
show
|
|||
71 | 7 | } |
|
72 | |||
73 | /** |
||
74 | * @since 1.0 |
||
75 | * |
||
76 | * @param Store $store |
||
77 | * @param SemanticData $semanticData |
||
78 | * |
||
79 | * @return boolean |
||
80 | */ |
||
81 | 6 | public function invalidateCacheOnStoreUpdate( Store $store, SemanticData $semanticData = null ) { |
|
82 | |||
83 | 6 | if ( $semanticData === null ) { |
|
84 | 1 | return false; |
|
85 | } |
||
86 | |||
87 | 5 | $this->matchAllSubobjects( $store, $semanticData ); |
|
88 | |||
89 | 5 | if ( $this->hasSemanticDataDeviation( $store, $semanticData ) ) { |
|
90 | 3 | $this->purgeCache( $semanticData->getSubject() ); |
|
91 | 3 | LingoParser::purgeCache(); |
|
0 ignored issues
–
show
The method
Lingo\LingoParser::purgeCache() has been deprecated with message: 2.0.2
This method has been deprecated. The supplier of the class has supplied an explanatory message. The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead. ![]() |
|||
92 | } |
||
93 | |||
94 | 5 | return true; |
|
95 | } |
||
96 | |||
97 | /** |
||
98 | * @since 1.0 |
||
99 | * |
||
100 | * @param Store $store |
||
101 | * @param DIWikiPage $subject |
||
102 | * @param boolean|true $purgeLingo |
||
103 | * |
||
104 | * @return boolean |
||
105 | */ |
||
106 | 3 | public function invalidateCacheOnPageDelete( Store $store, DIWikiPage $subject, $purgeLingo = true ) { |
|
107 | |||
108 | 3 | $this->matchSubobjectsToSubject( $store, $subject ); |
|
109 | 3 | $this->purgeCache( $subject ); |
|
110 | |||
111 | 3 | if ( $purgeLingo ) { |
|
112 | 3 | LingoParser::purgeCache(); |
|
0 ignored issues
–
show
The method
Lingo\LingoParser::purgeCache() has been deprecated with message: 2.0.2
This method has been deprecated. The supplier of the class has supplied an explanatory message. The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead. ![]() |
|||
113 | } |
||
114 | |||
115 | 3 | return true; |
|
116 | } |
||
117 | |||
118 | /** |
||
119 | * @since 1.0 |
||
120 | * |
||
121 | * @param LinkTarget $title |
||
122 | * |
||
123 | * @return boolean |
||
124 | */ |
||
125 | 1 | public function invalidateCacheOnPageMove( LinkTarget $title ) { |
|
126 | 1 | $this->purgeCache( DIWikiPage::newFromText( $title->getDBkey(), $title->getNamespace() )); |
|
127 | 1 | return true; |
|
128 | } |
||
129 | |||
130 | 5 | private function matchAllSubobjects( Store $store, SemanticData $semanticData ) { |
|
131 | |||
132 | 5 | $properties = $semanticData->getProperties(); |
|
133 | |||
134 | 5 | if ( array_key_exists( DIProperty::TYPE_SUBOBJECT, $properties ) ) { |
|
135 | 1 | foreach ( $semanticData->getPropertyValues( $properties[ DIProperty::TYPE_SUBOBJECT ] ) as $subobject ) { |
|
136 | 1 | $this->invalidateCacheOnStoreUpdate( |
|
137 | 1 | $store, |
|
138 | 1 | $semanticData->findSubSemanticData( $subobject->getSubobjectName() ), |
|
0 ignored issues
–
show
It seems like you code against a specific sub-type and not the parent class
SMWDataItem as the method getSubobjectName() does only exist in the following sub-classes of SMWDataItem : SMWDIWikiPage , SMW\DIWikiPage . Maybe you want to instanceof check for one of these explicitly?
Let’s take a look at an example: abstract class User
{
/** @return string */
abstract public function getPassword();
}
class MyUser extends User
{
public function getPassword()
{
// return something
}
public function getDisplayName()
{
// return some name.
}
}
class AuthSystem
{
public function authenticate(User $user)
{
$this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
// do something.
}
}
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break. Available Fixes
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types
inside the if block in such a case.
![]() |
|||
139 | 1 | false |
|
0 ignored issues
–
show
The call to
CacheInvalidator::invalidateCacheOnStoreUpdate() has too many arguments starting with false .
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue. If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. In this case you can add the ![]() |
|||
140 | ); |
||
141 | } |
||
142 | } |
||
143 | 5 | } |
|
144 | |||
145 | 3 | private function matchSubobjectsToSubject( Store $store, DIWikiPage $subject ) { |
|
146 | |||
147 | 3 | $properties = $store->getProperties( $subject ); |
|
148 | |||
149 | 3 | if ( array_key_exists( DIProperty::TYPE_SUBOBJECT, $properties ) ) { |
|
150 | 1 | foreach ( $store->getPropertyValues( $subject, $properties[ DIProperty::TYPE_SUBOBJECT ] ) as $subobject ) { |
|
151 | $this->invalidateCacheOnPageDelete( |
||
152 | $store, |
||
153 | $subobject->getSubject(), |
||
154 | false |
||
155 | ); |
||
156 | } |
||
157 | } |
||
158 | 3 | } |
|
159 | |||
160 | 5 | private function hasSemanticDataDeviation( Store $store, SemanticData $semanticData ) { |
|
161 | |||
162 | 5 | $dataComparator = new SemanticDataComparator( $store, $semanticData ); |
|
163 | |||
164 | 5 | return $dataComparator->compareForProperty( PropertyRegistrationHelper::SG_TERM ) || |
|
165 | 5 | $dataComparator->compareForProperty( PropertyRegistrationHelper::SG_DEFINITION ) || |
|
166 | 5 | $dataComparator->compareForProperty( PropertyRegistrationHelper::SG_LINK ) || |
|
167 | 5 | $dataComparator->compareForProperty( PropertyRegistrationHelper::SG_STYLE ); |
|
168 | } |
||
169 | |||
170 | 6 | private function purgeCache( DIWikiPage $subject ) { |
|
171 | |||
172 | 6 | $this->glossaryCache->getCache()->delete( |
|
173 | 6 | $this->glossaryCache->getKeyForSubject( $subject ) |
|
174 | ); |
||
175 | |||
176 | 6 | return true; |
|
177 | } |
||
178 | |||
179 | } |
||
180 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: