Skip to content

Commit 36ba540

Browse files
committed
Use PHP 5.6 language features
1 parent 4b2f5a3 commit 36ba540

23 files changed

+239
-234
lines changed

lib/Sabberworm/CSS/CSSList/CSSBlockList.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ protected function allValues($oElement, &$aResult, $sSearchString = null, $bSear
6868

6969
protected function allSelectors(&$aResult, $sSpecificitySearch = null)
7070
{
71-
$aDeclarationBlocks = array();
71+
$aDeclarationBlocks = [];
7272
$this->allDeclarationBlocks($aDeclarationBlocks);
7373
foreach ($aDeclarationBlocks as $oBlock) {
7474
foreach ($oBlock->getSelectors() as $oSelector) {

lib/Sabberworm/CSS/CSSList/CSSList.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ abstract class CSSList implements Renderable, Commentable
4646
*/
4747
public function __construct($iLineNo = 0)
4848
{
49-
$this->aComments = array();
50-
$this->aContents = array();
49+
$this->aComments = [];
50+
$this->aContents = [];
5151
$this->iLineNo = $iLineNo;
5252
}
5353

@@ -130,14 +130,14 @@ private static function parseAtRule(ParserState $oParserState)
130130
$oParserState->consumeWhiteSpace();
131131
$sMediaQuery = null;
132132
if (!$oParserState->comes(';')) {
133-
$sMediaQuery = trim($oParserState->consumeUntil(array(';', ParserState::EOF)));
133+
$sMediaQuery = trim($oParserState->consumeUntil([';', ParserState::EOF]));
134134
}
135-
$oParserState->consumeUntil(array(';', ParserState::EOF), true, true);
135+
$oParserState->consumeUntil([';', ParserState::EOF], true, true);
136136
return new Import($oLocation, $sMediaQuery ?: null, $iIdentifierLineNum);
137137
} elseif ($sIdentifier === 'charset') {
138138
$sCharset = CSSString::parse($oParserState);
139139
$oParserState->consumeWhiteSpace();
140-
$oParserState->consumeUntil(array(';', ParserState::EOF), true, true);
140+
$oParserState->consumeUntil([';', ParserState::EOF], true, true);
141141
return new Charset($sCharset, $iIdentifierLineNum);
142142
} elseif (self::identifierIs($sIdentifier, 'keyframes')) {
143143
$oResult = new KeyFrame($iIdentifierLineNum);
@@ -155,7 +155,7 @@ private static function parseAtRule(ParserState $oParserState)
155155
$sPrefix = $mUrl;
156156
$mUrl = Value::parsePrimitiveValue($oParserState);
157157
}
158-
$oParserState->consumeUntil(array(';', ParserState::EOF), true, true);
158+
$oParserState->consumeUntil([';', ParserState::EOF], true, true);
159159
if ($sPrefix !== null && !is_string($sPrefix)) {
160160
throw new UnexpectedTokenException('Wrong namespace prefix', $sPrefix, 'custom', $iIdentifierLineNum);
161161
}
@@ -271,7 +271,7 @@ public function replace($oOldItem, $mNewItem)
271271
if (is_array($mNewItem)) {
272272
array_splice($this->aContents, $iKey, 1, $mNewItem);
273273
} else {
274-
array_splice($this->aContents, $iKey, 1, array($mNewItem));
274+
array_splice($this->aContents, $iKey, 1, [$mNewItem]);
275275
}
276276
return true;
277277
}
@@ -284,7 +284,7 @@ public function replace($oOldItem, $mNewItem)
284284
*/
285285
public function setContents(array $aContents)
286286
{
287-
$this->aContents = array();
287+
$this->aContents = [];
288288
foreach ($aContents as $content) {
289289
$this->append($content);
290290
}

lib/Sabberworm/CSS/CSSList/Document.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public static function parse(ParserState $oParserState)
3737
*/
3838
public function getAllDeclarationBlocks()
3939
{
40-
$aResult = array();
40+
$aResult = [];
4141
$this->allDeclarationBlocks($aResult);
4242
return $aResult;
4343
}
@@ -55,7 +55,7 @@ public function getAllSelectors()
5555
*/
5656
public function getAllRuleSets()
5757
{
58-
$aResult = array();
58+
$aResult = [];
5959
$this->allRuleSets($aResult);
6060
return $aResult;
6161
}
@@ -74,7 +74,7 @@ public function getAllValues($mElement = null, $bSearchInFunctionArguments = fal
7474
$sSearchString = $mElement;
7575
$mElement = $this;
7676
}
77-
$aResult = array();
77+
$aResult = [];
7878
$this->allValues($mElement, $aResult, $sSearchString, $bSearchInFunctionArguments);
7979
return $aResult;
8080
}
@@ -87,7 +87,7 @@ public function getAllValues($mElement = null, $bSearchInFunctionArguments = fal
8787
*/
8888
public function getSelectorsBySpecificity($sSpecificitySearch = null)
8989
{
90-
$aResult = array();
90+
$aResult = [];
9191
$this->allSelectors($aResult, $sSpecificitySearch);
9292
return $aResult;
9393
}

lib/Sabberworm/CSS/OutputFormat.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Sabberworm\CSS;
44

55
use Sabberworm\CSS\Parsing\OutputException;
6+
use Sabberworm\CSS\OutputFormatter;
67

78
/**
89
* Class OutputFormat
@@ -81,7 +82,7 @@ public function __construct()
8182

8283
public function get($sName)
8384
{
84-
$aVarPrefixes = array('a', 's', 'm', 'b', 'f', 'o', 'c', 'i');
85+
$aVarPrefixes = ['a', 's', 'm', 'b', 'f', 'o', 'c', 'i'];
8586
foreach ($aVarPrefixes as $sPrefix) {
8687
$sFieldName = $sPrefix . ucfirst($sName);
8788
if (isset($this->$sFieldName)) {
@@ -93,11 +94,11 @@ public function get($sName)
9394

9495
public function set($aNames, $mValue)
9596
{
96-
$aVarPrefixes = array('a', 's', 'm', 'b', 'f', 'o', 'c', 'i');
97+
$aVarPrefixes = ['a', 's', 'm', 'b', 'f', 'o', 'c', 'i'];
9798
if (is_string($aNames) && strpos($aNames, '*') !== false) {
98-
$aNames = array(str_replace('*', 'Before', $aNames), str_replace('*', 'Between', $aNames), str_replace('*', 'After', $aNames));
99+
$aNames = [str_replace('*', 'Before', $aNames), str_replace('*', 'Between', $aNames), str_replace('*', 'After', $aNames)];
99100
} elseif (!is_array($aNames)) {
100-
$aNames = array($aNames);
101+
$aNames = [$aNames];
101102
}
102103
foreach ($aVarPrefixes as $sPrefix) {
103104
$bDidReplace = false;
@@ -122,8 +123,8 @@ public function __call($sMethodName, $aArguments)
122123
return $this->set(substr($sMethodName, 3), $aArguments[0]);
123124
} elseif (strpos($sMethodName, 'get') === 0) {
124125
return $this->get(substr($sMethodName, 3));
125-
} elseif (method_exists('\\Sabberworm\\CSS\\OutputFormatter', $sMethodName)) {
126-
return call_user_func_array(array($this->getFormatter(), $sMethodName), $aArguments);
126+
} elseif (method_exists(OutputFormatter::class, $sMethodName)) {
127+
return call_user_func_array([$this->getFormatter(), $sMethodName], $aArguments);
127128
} else {
128129
throw new \Exception('Unknown OutputFormat method called: ' . $sMethodName);
129130
}
@@ -197,7 +198,7 @@ public static function createCompact()
197198
public static function createPretty()
198199
{
199200
$format = self::create();
200-
$format->set('Space*Rules', "\n")->set('Space*Blocks', "\n")->setSpaceBetweenBlocks("\n\n")->set('SpaceAfterListArgumentSeparator', array('default' => '', ',' => ' '));
201+
$format->set('Space*Rules', "\n")->set('Space*Blocks', "\n")->setSpaceBetweenBlocks("\n\n")->set('SpaceAfterListArgumentSeparator', ['default' => '', ',' => ' ']);
201202
return $format;
202203
}
203204
}

lib/Sabberworm/CSS/Parsing/ParserState.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ public function parseCharacter($bIsForIdentifier)
134134

135135
public function consumeWhiteSpace()
136136
{
137-
$comments = array();
137+
$comments = [];
138138
do {
139139
while (preg_match('/\\s/isSu', $this->peek()) === 1) {
140140
$this->consume(1);
@@ -238,9 +238,9 @@ public function isEnd()
238238
return $this->iCurrentPosition >= $this->iLength;
239239
}
240240

241-
public function consumeUntil($aEnd, $bIncludeEnd = false, $consumeEnd = false, array &$comments = array())
241+
public function consumeUntil($aEnd, $bIncludeEnd = false, $consumeEnd = false, array &$comments = [])
242242
{
243-
$aEnd = is_array($aEnd) ? $aEnd : array($aEnd);
243+
$aEnd = is_array($aEnd) ? $aEnd : [$aEnd];
244244
$out = '';
245245
$start = $this->iCurrentPosition;
246246

@@ -329,15 +329,15 @@ private function strsplit($sString)
329329
return preg_split('//u', $sString, null, PREG_SPLIT_NO_EMPTY);
330330
} else {
331331
$iLength = mb_strlen($sString, $this->sCharset);
332-
$aResult = array();
332+
$aResult = [];
333333
for ($i = 0; $i < $iLength; ++$i) {
334334
$aResult[] = mb_substr($sString, $i, 1, $this->sCharset);
335335
}
336336
return $aResult;
337337
}
338338
} else {
339339
if ($sString === '') {
340-
return array();
340+
return [];
341341
} else {
342342
return str_split($sString);
343343
}

lib/Sabberworm/CSS/Property/CSSNamespace.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public function __construct($mUrl, $sPrefix = null, $iLineNo = 0)
1717
$this->mUrl = $mUrl;
1818
$this->sPrefix = $sPrefix;
1919
$this->iLineNo = $iLineNo;
20-
$this->aComments = array();
20+
$this->aComments = [];
2121
}
2222

2323
/**
@@ -76,7 +76,7 @@ public function atRuleName()
7676
*/
7777
public function atRuleArgs()
7878
{
79-
$aResult = array($this->mUrl);
79+
$aResult = [$this->mUrl];
8080
if ($this->sPrefix) {
8181
array_unshift($aResult, $this->sPrefix);
8282
}

lib/Sabberworm/CSS/Property/Charset.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function __construct($sCharset, $iLineNo = 0)
3434
{
3535
$this->sCharset = $sCharset;
3636
$this->iLineNo = $iLineNo;
37-
$this->aComments = array();
37+
$this->aComments = [];
3838
}
3939

4040
/**

lib/Sabberworm/CSS/Property/Import.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function __construct(URL $oLocation, $sMediaQuery, $iLineNo = 0)
3939
$this->oLocation = $oLocation;
4040
$this->sMediaQuery = $sMediaQuery;
4141
$this->iLineNo = $iLineNo;
42-
$this->aComments = array();
42+
$this->aComments = [];
4343
}
4444

4545
/**
@@ -88,7 +88,7 @@ public function atRuleName()
8888
*/
8989
public function atRuleArgs()
9090
{
91-
$aResult = array($this->oLocation);
91+
$aResult = [$this->oLocation];
9292
if ($this->sMediaQuery) {
9393
array_push($aResult, $this->sMediaQuery);
9494
}

lib/Sabberworm/CSS/Rule/Rule.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ public function __construct($sRule, $iLineNo = 0, $iColNo = 0)
2828
$this->sRule = $sRule;
2929
$this->mValue = null;
3030
$this->bIsImportant = false;
31-
$this->aIeHack = array();
31+
$this->aIeHack = [];
3232
$this->iLineNo = $iLineNo;
3333
$this->iColNo = $iColNo;
34-
$this->aComments = array();
34+
$this->aComments = [];
3535
}
3636

3737
public static function parse(ParserState $oParserState)
@@ -69,9 +69,9 @@ public static function parse(ParserState $oParserState)
6969
private static function listDelimiterForRule($sRule)
7070
{
7171
if (preg_match('/^font($|-)/', $sRule)) {
72-
return array(',', '/', ' ');
72+
return [',', '/', ' '];
7373
}
74-
return array(',', ' ', '/');
74+
return [',', ' ', '/'];
7575
}
7676

7777
/**
@@ -158,19 +158,19 @@ public function setValues($aSpaceSeparatedValues)
158158
public function getValues()
159159
{
160160
if (!$this->mValue instanceof RuleValueList) {
161-
return array(array($this->mValue));
161+
return [[$this->mValue]];
162162
}
163163
if ($this->mValue->getListSeparator() === ',') {
164-
return array($this->mValue->getListComponents());
164+
return [$this->mValue->getListComponents()];
165165
}
166-
$aResult = array();
166+
$aResult = [];
167167
foreach ($this->mValue->getListComponents() as $mValue) {
168168
if (!$mValue instanceof RuleValueList || $mValue->getListSeparator() !== ',') {
169-
$aResult[] = array($mValue);
169+
$aResult[] = [$mValue];
170170
continue;
171171
}
172172
if ($this->mValue->getListSeparator() === ' ' || count($aResult) === 0) {
173-
$aResult[] = array();
173+
$aResult[] = [];
174174
}
175175
foreach ($mValue->getListComponents() as $mValue) {
176176
$aResult[count($aResult) - 1][] = $mValue;
@@ -185,7 +185,7 @@ public function getValues()
185185
public function addValue($mValue, $sType = ' ')
186186
{
187187
if (!is_array($mValue)) {
188-
$mValue = array($mValue);
188+
$mValue = [$mValue];
189189
}
190190
if (!$this->mValue instanceof RuleValueList || $this->mValue->getListSeparator() !== $sType) {
191191
$mCurrentValue = $this->mValue;

0 commit comments

Comments
 (0)