These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | use SMW\DataValues\ValueFormatters\DataValueFormatter; |
||
4 | |||
5 | /** |
||
6 | * This datavalue implements String-Datavalues suitable for defining |
||
7 | * String-types of properties. |
||
8 | * |
||
9 | * @author Nikolas Iwan |
||
10 | * @author Markus Krötzsch |
||
11 | * @ingroup SMWDataValues |
||
12 | */ |
||
13 | class SMWStringValue extends SMWDataValue { |
||
14 | |||
15 | /** |
||
16 | * @see DataValue::parseUserValue |
||
17 | * |
||
18 | * @param string $value |
||
19 | */ |
||
20 | 70 | protected function parseUserValue( $value ) { |
|
21 | |||
22 | 70 | if ( $value === '' ) { |
|
23 | 1 | $this->addErrorMsg( 'smw_emptystring' ); |
|
24 | } |
||
25 | |||
26 | 70 | $this->m_dataitem = new SMWDIBlob( $value ); |
|
27 | 70 | } |
|
28 | |||
29 | /** |
||
30 | * @see SMWDataValue::loadDataItem() |
||
31 | * @param $dataitem SMWDataItem |
||
32 | * @return boolean |
||
33 | */ |
||
34 | 60 | protected function loadDataItem( SMWDataItem $dataItem ) { |
|
35 | 60 | if ( $dataItem instanceof SMWDIBlob ) { |
|
36 | 60 | $this->m_caption = false; |
|
0 ignored issues
–
show
|
|||
37 | 60 | $this->m_dataitem = $dataItem; |
|
38 | 60 | return true; |
|
39 | } else { |
||
40 | return false; |
||
41 | } |
||
42 | } |
||
43 | |||
44 | 60 | public function getShortWikiText( $linker = null ) { |
|
45 | 60 | return $this->getDataValueFormatter()->format( DataValueFormatter::WIKI_SHORT, $linker ); |
|
46 | } |
||
47 | |||
48 | 1 | public function getShortHTMLText( $linker = null ) { |
|
49 | 1 | return $this->getDataValueFormatter()->format( DataValueFormatter::HTML_SHORT, $linker ); |
|
50 | } |
||
51 | |||
52 | public function getLongWikiText( $linker = null ) { |
||
53 | return $this->getDataValueFormatter()->format( DataValueFormatter::WIKI_LONG, $linker ); |
||
54 | } |
||
55 | |||
56 | /** |
||
57 | * @todo Rather parse input to obtain properly formatted HTML. |
||
58 | */ |
||
59 | 1 | public function getLongHTMLText( $linker = null ) { |
|
60 | 1 | return $this->getDataValueFormatter()->format( DataValueFormatter::HTML_LONG, $linker ); |
|
61 | } |
||
62 | |||
63 | 53 | public function getWikiValue() { |
|
64 | 53 | return $this->getDataValueFormatter()->format( DataValueFormatter::VALUE ); |
|
65 | } |
||
66 | |||
67 | 2 | public function getWikiValueForLengthOf( $length ) { |
|
68 | |||
69 | 2 | if ( mb_strlen( $this->getWikiValue() ) > $length ) { |
|
70 | 1 | return mb_substr( $this->getWikiValue(), 0, $length ); |
|
71 | } |
||
72 | |||
73 | 2 | return $this->getWikiValue(); |
|
74 | } |
||
75 | |||
76 | public function getInfolinks() { |
||
77 | if ( $this->m_typeid != '_cod' ) { |
||
78 | return parent::getInfolinks(); |
||
79 | } else { |
||
80 | return $this->m_infolinks; |
||
81 | } |
||
82 | } |
||
83 | |||
84 | protected function getServiceLinkParams() { |
||
85 | // Create links to mapping services based on a wiki-editable message. The parameters |
||
86 | // available to the message are: |
||
87 | // $1: urlencoded string |
||
88 | if ( $this->isValid() ) { |
||
89 | return array( rawurlencode( $this->m_dataitem->getString() ) ); |
||
90 | } else { |
||
91 | return false; |
||
92 | } |
||
93 | } |
||
94 | |||
95 | } |
||
96 |
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.