These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /** |
||
3 | * @ingroup SMWDataValues |
||
4 | */ |
||
5 | |||
6 | /** |
||
7 | * This datavalue is used as a container for concept descriptions as used |
||
8 | * on Concept pages with the #concept parserfunction. It has a somewhat |
||
9 | * non-standard interface as compared to other datavalues, but this is not |
||
10 | * an issue. |
||
11 | * |
||
12 | * @author Markus Krötzsch |
||
13 | * @ingroup SMWDataValues |
||
14 | */ |
||
15 | class SMWConceptValue extends SMWDataValue { |
||
0 ignored issues
–
show
|
|||
16 | |||
17 | protected function parseUserValue( $value ) { |
||
18 | throw new Exception( 'Concepts cannot be initialized from user-provided strings. This should not happen.' ); |
||
19 | } |
||
20 | |||
21 | /** |
||
22 | * @see SMWDataValue::loadDataItem() |
||
23 | * @param $dataItem SMWDataItem |
||
24 | * @return boolean |
||
25 | */ |
||
26 | protected function loadDataItem( SMWDataItem $dataItem ) { |
||
27 | |||
28 | if ( $dataItem->getDIType() !== SMWDataItem::TYPE_CONCEPT ) { |
||
29 | return false; |
||
30 | } |
||
31 | |||
32 | $this->m_dataitem = $dataItem; |
||
33 | $this->m_caption = $dataItem->getConceptQuery(); // probably useless |
||
0 ignored issues
–
show
It seems like you code against a specific sub-type and not the parent class
SMWDataItem as the method getConceptQuery() does only exist in the following sub-classes of SMWDataItem : SMWDIConcept , SMW\DIConcept . 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.
Loading history...
|
|||
34 | |||
35 | return true; |
||
36 | } |
||
37 | |||
38 | protected function clear() { |
||
39 | $this->m_dataitem = new \SMW\DIConcept( '', '', 0, -1, -1, $this->m_typeid ); |
||
0 ignored issues
–
show
The call to
DIConcept::__construct() has too many arguments starting with $this->m_typeid .
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
Loading history...
|
|||
40 | } |
||
41 | |||
42 | public function getShortWikiText( $linked = null ) { |
||
43 | return $this->m_caption; |
||
44 | } |
||
45 | |||
46 | public function getShortHTMLText( $linker = null ) { |
||
47 | return $this->getShortWikiText( $linker ); // should be save (based on xsdvalue) |
||
48 | } |
||
49 | |||
50 | public function getLongWikiText( $linked = null ) { |
||
51 | if ( !$this->isValid() ) { |
||
52 | return $this->getErrorText(); |
||
53 | } else { |
||
54 | return $this->m_caption; |
||
55 | } |
||
56 | } |
||
57 | |||
58 | public function getLongHTMLText( $linker = null ) { |
||
59 | if ( !$this->isValid() ) { |
||
60 | return $this->getErrorText(); |
||
61 | } else { |
||
62 | return $this->m_caption; // should be save (based on xsdvalue) |
||
63 | } |
||
64 | } |
||
65 | |||
66 | public function getWikiValue() { |
||
67 | /// This should not be used for anything. This class does not support wiki values. |
||
68 | return str_replace( array( '<', '>', '&' ), array( '<', '>', '&' ), $this->m_dataitem->getConceptQuery() ); |
||
0 ignored issues
–
show
It seems like you code against a specific sub-type and not the parent class
SMWDataItem as the method getConceptQuery() does only exist in the following sub-classes of SMWDataItem : SMWDIConcept , SMW\DIConcept . 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.
Loading history...
|
|||
69 | } |
||
70 | |||
71 | /// Return the concept's defining text (in SMW query syntax) |
||
72 | public function getConceptText() { |
||
73 | return $this->m_dataitem->getConceptQuery(); |
||
0 ignored issues
–
show
It seems like you code against a specific sub-type and not the parent class
SMWDataItem as the method getConceptQuery() does only exist in the following sub-classes of SMWDataItem : SMWDIConcept , SMW\DIConcept . 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.
Loading history...
|
|||
74 | } |
||
75 | |||
76 | /// Return the optional concept documentation. |
||
77 | public function getDocu() { |
||
78 | return $this->m_dataitem->getDocumentation(); |
||
0 ignored issues
–
show
It seems like you code against a specific sub-type and not the parent class
SMWDataItem as the method getDocumentation() does only exist in the following sub-classes of SMWDataItem : SMWDIConcept , SMW\DIConcept . 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.
Loading history...
|
|||
79 | } |
||
80 | |||
81 | /// Return the concept's size (a metric used to estimate computation complexity). |
||
82 | public function getSize() { |
||
83 | return $this->m_dataitem->getSize(); |
||
0 ignored issues
–
show
It seems like you code against a specific sub-type and not the parent class
SMWDataItem as the method getSize() does only exist in the following sub-classes of SMWDataItem : SMWDIConcept , SMW\DIConcept . 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.
Loading history...
|
|||
84 | } |
||
85 | |||
86 | /// Return the concept's depth (a metric used to estimate computation complexity). |
||
87 | public function getDepth() { |
||
88 | return $this->m_dataitem->getDepth(); |
||
0 ignored issues
–
show
It seems like you code against a specific sub-type and not the parent class
SMWDataItem as the method getDepth() does only exist in the following sub-classes of SMWDataItem : SMWDIConcept , SMW\DIConcept . 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.
Loading history...
|
|||
89 | } |
||
90 | |||
91 | /// Return the concept's query feature bit field (a metric used to estimate computation complexity). |
||
92 | public function getQueryFeatures() { |
||
93 | return $this->m_dataitem->getQueryFeatures(); |
||
0 ignored issues
–
show
It seems like you code against a specific sub-type and not the parent class
SMWDataItem as the method getQueryFeatures() does only exist in the following sub-classes of SMWDataItem : SMWDIConcept , SMW\DIConcept . 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.
Loading history...
|
|||
94 | } |
||
95 | |||
96 | } |
||
97 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.