Skip to content
This repository has been archived by the owner on May 26, 2022. It is now read-only.

Commit

Permalink
Automated native_function_invocation fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
drowe-wayfair authored and adrilo committed Nov 18, 2019
1 parent 94b6541 commit eb88bb4
Show file tree
Hide file tree
Showing 62 changed files with 237 additions and 237 deletions.
22 changes: 11 additions & 11 deletions src/Spout/Autoloader/Psr4Autoloader.php
Expand Up @@ -23,7 +23,7 @@ class Psr4Autoloader
*/
public function register()
{
spl_autoload_register([$this, 'loadClass']);
\spl_autoload_register([$this, 'loadClass']);
}

/**
Expand All @@ -40,10 +40,10 @@ public function register()
public function addNamespace($prefix, $baseDir, $prepend = false)
{
// normalize namespace prefix
$prefix = trim($prefix, '\\') . '\\';
$prefix = \trim($prefix, '\\') . '\\';

// normalize the base directory with a trailing separator
$baseDir = rtrim($baseDir, DIRECTORY_SEPARATOR) . '/';
$baseDir = \rtrim($baseDir, DIRECTORY_SEPARATOR) . '/';

// initialize the namespace prefix array
if (isset($this->prefixes[$prefix]) === false) {
Expand All @@ -52,9 +52,9 @@ public function addNamespace($prefix, $baseDir, $prepend = false)

// retain the base directory for the namespace prefix
if ($prepend) {
array_unshift($this->prefixes[$prefix], $baseDir);
\array_unshift($this->prefixes[$prefix], $baseDir);
} else {
array_push($this->prefixes[$prefix], $baseDir);
\array_push($this->prefixes[$prefix], $baseDir);
}
}

Expand All @@ -72,12 +72,12 @@ public function loadClass($class)

// work backwards through the namespace names of the fully-qualified
// class name to find a mapped file name
while (($pos = strrpos($prefix, '\\')) !== false) {
while (($pos = \strrpos($prefix, '\\')) !== false) {
// retain the trailing namespace separator in the prefix
$prefix = substr($class, 0, $pos + 1);
$prefix = \substr($class, 0, $pos + 1);

// the rest is the relative class name
$relativeClass = substr($class, $pos + 1);
$relativeClass = \substr($class, $pos + 1);

// try to load a mapped file for the prefix and relative class
$mappedFile = $this->loadMappedFile($prefix, $relativeClass);
Expand All @@ -87,7 +87,7 @@ public function loadClass($class)

// remove the trailing namespace separator for the next iteration
// of strrpos()
$prefix = rtrim($prefix, '\\');
$prefix = \rtrim($prefix, '\\');
}

// never found a mapped file
Expand Down Expand Up @@ -115,7 +115,7 @@ protected function loadMappedFile($prefix, $relativeClass)
// replace namespace separators with directory separators
// in the relative class name, append with .php
$file = $baseDir
. str_replace('\\', '/', $relativeClass)
. \str_replace('\\', '/', $relativeClass)
. '.php';

// if the mapped file exists, require it
Expand All @@ -137,7 +137,7 @@ protected function loadMappedFile($prefix, $relativeClass)
*/
protected function requireFile($file)
{
if (file_exists($file)) {
if (\file_exists($file)) {
require $file;

return true;
Expand Down
2 changes: 1 addition & 1 deletion src/Spout/Autoloader/autoload.php
Expand Up @@ -8,7 +8,7 @@
* @var string
* Full path to "src/Spout" which is what we want "Box\Spout" to map to.
*/
$srcBaseDirectory = dirname(dirname(__FILE__));
$srcBaseDirectory = \dirname(\dirname(__FILE__));

$loader = new Psr4Autoloader();
$loader->register();
Expand Down
4 changes: 2 additions & 2 deletions src/Spout/Common/Entity/Row.php
Expand Up @@ -95,7 +95,7 @@ public function getNumCells()
return 0;
}

return max(array_keys($this->cells)) + 1;
return \max(\array_keys($this->cells)) + 1;
}

/**
Expand All @@ -122,7 +122,7 @@ public function setStyle($style)
*/
public function toArray()
{
return array_map(function (Cell $cell) {
return \array_map(function (Cell $cell) {
return $cell->getValue();
}, $this->cells);
}
Expand Down
6 changes: 3 additions & 3 deletions src/Spout/Common/Entity/Style/BorderPart.php
Expand Up @@ -93,7 +93,7 @@ public function getName()
*/
public function setName($name)
{
if (!in_array($name, self::$allowedNames)) {
if (!\in_array($name, self::$allowedNames)) {
throw new InvalidNameException($name);
}
$this->name = $name;
Expand All @@ -114,7 +114,7 @@ public function getStyle()
*/
public function setStyle($style)
{
if (!in_array($style, self::$allowedStyles)) {
if (!\in_array($style, self::$allowedStyles)) {
throw new InvalidStyleException($style);
}
$this->style = $style;
Expand Down Expand Up @@ -152,7 +152,7 @@ public function getWidth()
*/
public function setWidth($width)
{
if (!in_array($width, self::$allowedWidths)) {
if (!\in_array($width, self::$allowedWidths)) {
throw new InvalidWidthException($width);
}
$this->width = $width;
Expand Down
6 changes: 3 additions & 3 deletions src/Spout/Common/Entity/Style/Color.php
Expand Up @@ -38,7 +38,7 @@ public static function rgb($red, $green, $blue)
self::throwIfInvalidColorComponentValue($green);
self::throwIfInvalidColorComponentValue($blue);

return strtoupper(
return \strtoupper(
self::convertColorComponentToHex($red) .
self::convertColorComponentToHex($green) .
self::convertColorComponentToHex($blue)
Expand All @@ -54,7 +54,7 @@ public static function rgb($red, $green, $blue)
*/
protected static function throwIfInvalidColorComponentValue($colorComponent)
{
if (!is_int($colorComponent) || $colorComponent < 0 || $colorComponent > 255) {
if (!\is_int($colorComponent) || $colorComponent < 0 || $colorComponent > 255) {
throw new InvalidColorException("The RGB components must be between 0 and 255. Received: $colorComponent");
}
}
Expand All @@ -67,7 +67,7 @@ protected static function throwIfInvalidColorComponentValue($colorComponent)
*/
protected static function convertColorComponentToHex($colorComponent)
{
return str_pad(dechex($colorComponent), 2, '0', STR_PAD_LEFT);
return \str_pad(\dechex($colorComponent), 2, '0', STR_PAD_LEFT);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/Spout/Common/Helper/CellTypeHelper.php
Expand Up @@ -23,7 +23,7 @@ public static function isEmpty($value)
*/
public static function isNonEmptyString($value)
{
return (gettype($value) === 'string' && $value !== '');
return (\gettype($value) === 'string' && $value !== '');
}

/**
Expand All @@ -35,7 +35,7 @@ public static function isNonEmptyString($value)
*/
public static function isNumeric($value)
{
$valueType = gettype($value);
$valueType = \gettype($value);

return ($valueType === 'integer' || $valueType === 'double');
}
Expand All @@ -49,7 +49,7 @@ public static function isNumeric($value)
*/
public static function isBoolean($value)
{
return gettype($value) === 'boolean';
return \gettype($value) === 'boolean';
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/Spout/Common/Helper/EncodingHelper.php
Expand Up @@ -61,7 +61,7 @@ public function getBytesOffsetToSkipBOM($filePointer, $encoding)
$bomUsed = $this->supportedEncodingsWithBom[$encoding];

// we skip the N first bytes
$byteOffsetToSkipBom = strlen($bomUsed);
$byteOffsetToSkipBom = \strlen($bomUsed);
}

return $byteOffsetToSkipBom;
Expand All @@ -80,9 +80,9 @@ protected function hasBOM($filePointer, $encoding)

$this->globalFunctionsHelper->rewind($filePointer);

if (array_key_exists($encoding, $this->supportedEncodingsWithBom)) {
if (\array_key_exists($encoding, $this->supportedEncodingsWithBom)) {
$potentialBom = $this->supportedEncodingsWithBom[$encoding];
$numBytesInBom = strlen($potentialBom);
$numBytesInBom = \strlen($potentialBom);

$hasBOM = ($this->globalFunctionsHelper->fgets($filePointer, $numBytesInBom + 1) === $potentialBom);
}
Expand Down
8 changes: 4 additions & 4 deletions src/Spout/Common/Helper/Escaper/ODS.php
Expand Up @@ -18,14 +18,14 @@ public function escape($string)
{
// @NOTE: Using ENT_QUOTES as XML entities ('<', '>', '&') as well as
// single/double quotes (for XML attributes) need to be encoded.
if (defined('ENT_DISALLOWED')) {
if (\defined('ENT_DISALLOWED')) {
// 'ENT_DISALLOWED' ensures that invalid characters in the given document type are replaced.
// Otherwise control characters like a vertical tab "\v" will make the XML document unreadable by the XML processor
// @link https://github.com/box/spout/issues/329
$replacedString = htmlspecialchars($string, ENT_QUOTES | ENT_DISALLOWED, 'UTF-8');
$replacedString = \htmlspecialchars($string, ENT_QUOTES | ENT_DISALLOWED, 'UTF-8');
} else {
// We are on hhvm or any other engine that does not support ENT_DISALLOWED.
$escapedString = htmlspecialchars($string, ENT_QUOTES, 'UTF-8');
$escapedString = \htmlspecialchars($string, ENT_QUOTES, 'UTF-8');

// control characters values are from 0 to 1F (hex values) in the ASCII table
// some characters should not be escaped though: "\t", "\r" and "\n".
Expand All @@ -34,7 +34,7 @@ public function escape($string)
'\x0B-\x0C' .
// skipping "\r" (0xD)
'\x0E-\x1F]';
$replacedString = preg_replace("/$regexPattern/", '�', $escapedString);
$replacedString = \preg_replace("/$regexPattern/", '�', $escapedString);
}

return $replacedString;
Expand Down
22 changes: 11 additions & 11 deletions src/Spout/Common/Helper/Escaper/XLSX.php
Expand Up @@ -28,7 +28,7 @@ protected function initIfNeeded()
if (!$this->isAlreadyInitialized) {
$this->escapableControlCharactersPattern = $this->getEscapableControlCharactersPattern();
$this->controlCharactersEscapingMap = $this->getControlCharactersEscapingMap();
$this->controlCharactersEscapingReverseMap = array_flip($this->controlCharactersEscapingMap);
$this->controlCharactersEscapingReverseMap = \array_flip($this->controlCharactersEscapingMap);

$this->isAlreadyInitialized = true;
}
Expand All @@ -47,7 +47,7 @@ public function escape($string)
$escapedString = $this->escapeControlCharacters($string);
// @NOTE: Using ENT_QUOTES as XML entities ('<', '>', '&') as well as
// single/double quotes (for XML attributes) need to be encoded.
$escapedString = htmlspecialchars($escapedString, ENT_QUOTES, 'UTF-8');
$escapedString = \htmlspecialchars($escapedString, ENT_QUOTES, 'UTF-8');

return $escapedString;
}
Expand Down Expand Up @@ -103,10 +103,10 @@ protected function getControlCharactersEscapingMap()

// control characters values are from 0 to 1F (hex values) in the ASCII table
for ($charValue = 0x00; $charValue <= 0x1F; $charValue++) {
$character = chr($charValue);
if (preg_match("/{$this->escapableControlCharactersPattern}/", $character)) {
$charHexValue = dechex($charValue);
$escapedChar = '_x' . sprintf('%04s', strtoupper($charHexValue)) . '_';
$character = \chr($charValue);
if (\preg_match("/{$this->escapableControlCharactersPattern}/", $character)) {
$charHexValue = \dechex($charValue);
$escapedChar = '_x' . \sprintf('%04s', \strtoupper($charHexValue)) . '_';
$controlCharactersEscapingMap[$escapedChar] = $character;
}
}
Expand All @@ -132,11 +132,11 @@ protected function escapeControlCharacters($string)
$escapedString = $this->escapeEscapeCharacter($string);

// if no control characters
if (!preg_match("/{$this->escapableControlCharactersPattern}/", $escapedString)) {
if (!\preg_match("/{$this->escapableControlCharactersPattern}/", $escapedString)) {
return $escapedString;
}

return preg_replace_callback("/({$this->escapableControlCharactersPattern})/", function ($matches) {
return \preg_replace_callback("/({$this->escapableControlCharactersPattern})/", function ($matches) {
return $this->controlCharactersEscapingReverseMap[$matches[0]];
}, $escapedString);
}
Expand All @@ -149,7 +149,7 @@ protected function escapeControlCharacters($string)
*/
protected function escapeEscapeCharacter($string)
{
return preg_replace('/_(x[\dA-F]{4})_/', '_x005F_$1_', $string);
return \preg_replace('/_(x[\dA-F]{4})_/', '_x005F_$1_', $string);
}

/**
Expand All @@ -171,7 +171,7 @@ protected function unescapeControlCharacters($string)

foreach ($this->controlCharactersEscapingMap as $escapedCharValue => $charValue) {
// only unescape characters that don't contain the escaped escape character for now
$unescapedString = preg_replace("/(?<!_x005F)($escapedCharValue)/", $charValue, $unescapedString);
$unescapedString = \preg_replace("/(?<!_x005F)($escapedCharValue)/", $charValue, $unescapedString);
}

return $this->unescapeEscapeCharacter($unescapedString);
Expand All @@ -185,6 +185,6 @@ protected function unescapeControlCharacters($string)
*/
protected function unescapeEscapeCharacter($string)
{
return preg_replace('/_x005F(_x[\dA-F]{4}_)/', '$1', $string);
return \preg_replace('/_x005F(_x[\dA-F]{4}_)/', '$1', $string);
}
}
20 changes: 10 additions & 10 deletions src/Spout/Common/Helper/FileSystemHelper.php
Expand Up @@ -19,7 +19,7 @@ class FileSystemHelper implements FileSystemHelperInterface
*/
public function __construct($baseFolderPath)
{
$this->baseFolderRealPath = realpath($baseFolderPath);
$this->baseFolderRealPath = \realpath($baseFolderPath);
}

/**
Expand All @@ -36,7 +36,7 @@ public function createFolder($parentFolderPath, $folderName)

$folderPath = $parentFolderPath . '/' . $folderName;

$wasCreationSuccessful = mkdir($folderPath, 0777, true);
$wasCreationSuccessful = \mkdir($folderPath, 0777, true);
if (!$wasCreationSuccessful) {
throw new IOException("Unable to create folder: $folderPath");
}
Expand All @@ -60,7 +60,7 @@ public function createFileWithContents($parentFolderPath, $fileName, $fileConten

$filePath = $parentFolderPath . '/' . $fileName;

$wasCreationSuccessful = file_put_contents($filePath, $fileContents);
$wasCreationSuccessful = \file_put_contents($filePath, $fileContents);
if ($wasCreationSuccessful === false) {
throw new IOException("Unable to create file: $filePath");
}
Expand All @@ -79,8 +79,8 @@ public function deleteFile($filePath)
{
$this->throwIfOperationNotInBaseFolder($filePath);

if (file_exists($filePath) && is_file($filePath)) {
unlink($filePath);
if (\file_exists($filePath) && \is_file($filePath)) {
\unlink($filePath);
}
}

Expand All @@ -102,13 +102,13 @@ public function deleteFolderRecursively($folderPath)

foreach ($itemIterator as $item) {
if ($item->isDir()) {
rmdir($item->getPathname());
\rmdir($item->getPathname());
} else {
unlink($item->getPathname());
\unlink($item->getPathname());
}
}

rmdir($folderPath);
\rmdir($folderPath);
}

/**
Expand All @@ -122,8 +122,8 @@ public function deleteFolderRecursively($folderPath)
*/
protected function throwIfOperationNotInBaseFolder($operationFolderPath)
{
$operationFolderRealPath = realpath($operationFolderPath);
$isInBaseFolder = (strpos($operationFolderRealPath, $this->baseFolderRealPath) === 0);
$operationFolderRealPath = \realpath($operationFolderPath);
$isInBaseFolder = (\strpos($operationFolderRealPath, $this->baseFolderRealPath) === 0);
if (!$isInBaseFolder) {
throw new IOException("Cannot perform I/O operation outside of the base folder: {$this->baseFolderRealPath}");
}
Expand Down

0 comments on commit eb88bb4

Please sign in to comment.