Skip to content

Use PHP 5.6 language features #223

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/Sabberworm/CSS/CSSList/CSSBlockList.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ protected function allValues($oElement, &$aResult, $sSearchString = null, $bSear

protected function allSelectors(&$aResult, $sSpecificitySearch = null)
{
$aDeclarationBlocks = array();
$aDeclarationBlocks = [];
$this->allDeclarationBlocks($aDeclarationBlocks);
foreach ($aDeclarationBlocks as $oBlock) {
foreach ($oBlock->getSelectors() as $oSelector) {
Expand Down
16 changes: 8 additions & 8 deletions lib/Sabberworm/CSS/CSSList/CSSList.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ abstract class CSSList implements Renderable, Commentable
*/
public function __construct($iLineNo = 0)
{
$this->aComments = array();
$this->aContents = array();
$this->aComments = [];
$this->aContents = [];
$this->iLineNo = $iLineNo;
}

Expand Down Expand Up @@ -130,14 +130,14 @@ private static function parseAtRule(ParserState $oParserState)
$oParserState->consumeWhiteSpace();
$sMediaQuery = null;
if (!$oParserState->comes(';')) {
$sMediaQuery = trim($oParserState->consumeUntil(array(';', ParserState::EOF)));
$sMediaQuery = trim($oParserState->consumeUntil([';', ParserState::EOF]));
}
$oParserState->consumeUntil(array(';', ParserState::EOF), true, true);
$oParserState->consumeUntil([';', ParserState::EOF], true, true);
return new Import($oLocation, $sMediaQuery ?: null, $iIdentifierLineNum);
} elseif ($sIdentifier === 'charset') {
$sCharset = CSSString::parse($oParserState);
$oParserState->consumeWhiteSpace();
$oParserState->consumeUntil(array(';', ParserState::EOF), true, true);
$oParserState->consumeUntil([';', ParserState::EOF], true, true);
return new Charset($sCharset, $iIdentifierLineNum);
} elseif (self::identifierIs($sIdentifier, 'keyframes')) {
$oResult = new KeyFrame($iIdentifierLineNum);
Expand All @@ -155,7 +155,7 @@ private static function parseAtRule(ParserState $oParserState)
$sPrefix = $mUrl;
$mUrl = Value::parsePrimitiveValue($oParserState);
}
$oParserState->consumeUntil(array(';', ParserState::EOF), true, true);
$oParserState->consumeUntil([';', ParserState::EOF], true, true);
if ($sPrefix !== null && !is_string($sPrefix)) {
throw new UnexpectedTokenException('Wrong namespace prefix', $sPrefix, 'custom', $iIdentifierLineNum);
}
Expand Down Expand Up @@ -271,7 +271,7 @@ public function replace($oOldItem, $mNewItem)
if (is_array($mNewItem)) {
array_splice($this->aContents, $iKey, 1, $mNewItem);
} else {
array_splice($this->aContents, $iKey, 1, array($mNewItem));
array_splice($this->aContents, $iKey, 1, [$mNewItem]);
}
return true;
}
Expand All @@ -284,7 +284,7 @@ public function replace($oOldItem, $mNewItem)
*/
public function setContents(array $aContents)
{
$this->aContents = array();
$this->aContents = [];
foreach ($aContents as $content) {
$this->append($content);
}
Expand Down
8 changes: 4 additions & 4 deletions lib/Sabberworm/CSS/CSSList/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static function parse(ParserState $oParserState)
*/
public function getAllDeclarationBlocks()
{
$aResult = array();
$aResult = [];
$this->allDeclarationBlocks($aResult);
return $aResult;
}
Expand All @@ -55,7 +55,7 @@ public function getAllSelectors()
*/
public function getAllRuleSets()
{
$aResult = array();
$aResult = [];
$this->allRuleSets($aResult);
return $aResult;
}
Expand All @@ -74,7 +74,7 @@ public function getAllValues($mElement = null, $bSearchInFunctionArguments = fal
$sSearchString = $mElement;
$mElement = $this;
}
$aResult = array();
$aResult = [];
$this->allValues($mElement, $aResult, $sSearchString, $bSearchInFunctionArguments);
return $aResult;
}
Expand All @@ -87,7 +87,7 @@ public function getAllValues($mElement = null, $bSearchInFunctionArguments = fal
*/
public function getSelectorsBySpecificity($sSpecificitySearch = null)
{
$aResult = array();
$aResult = [];
$this->allSelectors($aResult, $sSpecificitySearch);
return $aResult;
}
Expand Down
15 changes: 8 additions & 7 deletions lib/Sabberworm/CSS/OutputFormat.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Sabberworm\CSS;

use Sabberworm\CSS\Parsing\OutputException;
use Sabberworm\CSS\OutputFormatter;

/**
* Class OutputFormat
Expand Down Expand Up @@ -81,7 +82,7 @@ public function __construct()

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

public function set($aNames, $mValue)
{
$aVarPrefixes = array('a', 's', 'm', 'b', 'f', 'o', 'c', 'i');
$aVarPrefixes = ['a', 's', 'm', 'b', 'f', 'o', 'c', 'i'];
if (is_string($aNames) && strpos($aNames, '*') !== false) {
$aNames = array(str_replace('*', 'Before', $aNames), str_replace('*', 'Between', $aNames), str_replace('*', 'After', $aNames));
$aNames = [str_replace('*', 'Before', $aNames), str_replace('*', 'Between', $aNames), str_replace('*', 'After', $aNames)];
} elseif (!is_array($aNames)) {
$aNames = array($aNames);
$aNames = [$aNames];
}
foreach ($aVarPrefixes as $sPrefix) {
$bDidReplace = false;
Expand All @@ -122,8 +123,8 @@ public function __call($sMethodName, $aArguments)
return $this->set(substr($sMethodName, 3), $aArguments[0]);
} elseif (strpos($sMethodName, 'get') === 0) {
return $this->get(substr($sMethodName, 3));
} elseif (method_exists('\\Sabberworm\\CSS\\OutputFormatter', $sMethodName)) {
return call_user_func_array(array($this->getFormatter(), $sMethodName), $aArguments);
} elseif (method_exists(OutputFormatter::class, $sMethodName)) {
return call_user_func_array([$this->getFormatter(), $sMethodName], $aArguments);
} else {
throw new \Exception('Unknown OutputFormat method called: ' . $sMethodName);
}
Expand Down Expand Up @@ -197,7 +198,7 @@ public static function createCompact()
public static function createPretty()
{
$format = self::create();
$format->set('Space*Rules', "\n")->set('Space*Blocks', "\n")->setSpaceBetweenBlocks("\n\n")->set('SpaceAfterListArgumentSeparator', array('default' => '', ',' => ' '));
$format->set('Space*Rules', "\n")->set('Space*Blocks', "\n")->setSpaceBetweenBlocks("\n\n")->set('SpaceAfterListArgumentSeparator', ['default' => '', ',' => ' ']);
return $format;
}
}
Expand Down
10 changes: 5 additions & 5 deletions lib/Sabberworm/CSS/Parsing/ParserState.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public function parseCharacter($bIsForIdentifier)

public function consumeWhiteSpace()
{
$comments = array();
$comments = [];
do {
while (preg_match('/\\s/isSu', $this->peek()) === 1) {
$this->consume(1);
Expand Down Expand Up @@ -238,9 +238,9 @@ public function isEnd()
return $this->iCurrentPosition >= $this->iLength;
}

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

Expand Down Expand Up @@ -329,15 +329,15 @@ private function strsplit($sString)
return preg_split('//u', $sString, null, PREG_SPLIT_NO_EMPTY);
} else {
$iLength = mb_strlen($sString, $this->sCharset);
$aResult = array();
$aResult = [];
for ($i = 0; $i < $iLength; ++$i) {
$aResult[] = mb_substr($sString, $i, 1, $this->sCharset);
}
return $aResult;
}
} else {
if ($sString === '') {
return array();
return [];
} else {
return str_split($sString);
}
Expand Down
4 changes: 2 additions & 2 deletions lib/Sabberworm/CSS/Property/CSSNamespace.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function __construct($mUrl, $sPrefix = null, $iLineNo = 0)
$this->mUrl = $mUrl;
$this->sPrefix = $sPrefix;
$this->iLineNo = $iLineNo;
$this->aComments = array();
$this->aComments = [];
}

/**
Expand Down Expand Up @@ -76,7 +76,7 @@ public function atRuleName()
*/
public function atRuleArgs()
{
$aResult = array($this->mUrl);
$aResult = [$this->mUrl];
if ($this->sPrefix) {
array_unshift($aResult, $this->sPrefix);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Sabberworm/CSS/Property/Charset.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function __construct($sCharset, $iLineNo = 0)
{
$this->sCharset = $sCharset;
$this->iLineNo = $iLineNo;
$this->aComments = array();
$this->aComments = [];
}

/**
Expand Down
4 changes: 2 additions & 2 deletions lib/Sabberworm/CSS/Property/Import.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function __construct(URL $oLocation, $sMediaQuery, $iLineNo = 0)
$this->oLocation = $oLocation;
$this->sMediaQuery = $sMediaQuery;
$this->iLineNo = $iLineNo;
$this->aComments = array();
$this->aComments = [];
}

/**
Expand Down Expand Up @@ -88,7 +88,7 @@ public function atRuleName()
*/
public function atRuleArgs()
{
$aResult = array($this->oLocation);
$aResult = [$this->oLocation];
if ($this->sMediaQuery) {
array_push($aResult, $this->sMediaQuery);
}
Expand Down
20 changes: 10 additions & 10 deletions lib/Sabberworm/CSS/Rule/Rule.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ public function __construct($sRule, $iLineNo = 0, $iColNo = 0)
$this->sRule = $sRule;
$this->mValue = null;
$this->bIsImportant = false;
$this->aIeHack = array();
$this->aIeHack = [];
$this->iLineNo = $iLineNo;
$this->iColNo = $iColNo;
$this->aComments = array();
$this->aComments = [];
}

public static function parse(ParserState $oParserState)
Expand Down Expand Up @@ -69,9 +69,9 @@ public static function parse(ParserState $oParserState)
private static function listDelimiterForRule($sRule)
{
if (preg_match('/^font($|-)/', $sRule)) {
return array(',', '/', ' ');
return [',', '/', ' '];
}
return array(',', ' ', '/');
return [',', ' ', '/'];
}

/**
Expand Down Expand Up @@ -158,19 +158,19 @@ public function setValues($aSpaceSeparatedValues)
public function getValues()
{
if (!$this->mValue instanceof RuleValueList) {
return array(array($this->mValue));
return [[$this->mValue]];
}
if ($this->mValue->getListSeparator() === ',') {
return array($this->mValue->getListComponents());
return [$this->mValue->getListComponents()];
}
$aResult = array();
$aResult = [];
foreach ($this->mValue->getListComponents() as $mValue) {
if (!$mValue instanceof RuleValueList || $mValue->getListSeparator() !== ',') {
$aResult[] = array($mValue);
$aResult[] = [$mValue];
continue;
}
if ($this->mValue->getListSeparator() === ' ' || count($aResult) === 0) {
$aResult[] = array();
$aResult[] = [];
}
foreach ($mValue->getListComponents() as $mValue) {
$aResult[count($aResult) - 1][] = $mValue;
Expand All @@ -185,7 +185,7 @@ public function getValues()
public function addValue($mValue, $sType = ' ')
{
if (!is_array($mValue)) {
$mValue = array($mValue);
$mValue = [$mValue];
}
if (!$this->mValue instanceof RuleValueList || $this->mValue->getListSeparator() !== $sType) {
$mCurrentValue = $this->mValue;
Expand Down
Loading