diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 1c0a674..e68314a 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -8,7 +8,7 @@ jobs: strategy: fail-fast: true matrix: - php: [7.1, 7.2, 7.3, 7.4, 8.0, 8.1] + php: [8.5] testsuite: ["unit"] name: PHPUnit - ${{ matrix.testsuite }} (PHP ${{ matrix.php }}) services: @@ -22,10 +22,10 @@ jobs: options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 steps: - name: Checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v5 - name: Cache dependencies - uses: actions/cache@v2 + uses: actions/cache@v4 with: path: ~/.composer/cache/files key: dependencies-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }} diff --git a/.gitignore b/.gitignore index 9cad150..f1d3d8c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ +composer.lock /vendor spoon/tests/tmp/spoon.zip +.phpunit.result.cache diff --git a/composer.json b/composer.json index f0d20c0..d094adf 100644 --- a/composer.json +++ b/composer.json @@ -11,9 +11,10 @@ } ], "require": { - "php": "^7.1|^8.0" + "php": "^8.5" }, "require-dev": { - "symfony/phpunit-bridge": "^5.3" + "symfony/phpunit-bridge": "^7.2", + "rector/rector": "*" } } diff --git a/composer.lock b/composer.lock deleted file mode 100644 index 2805c5d..0000000 --- a/composer.lock +++ /dev/null @@ -1,171 +0,0 @@ -{ - "_readme": [ - "This file locks the dependencies of your project to a known state", - "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", - "This file is @generated automatically" - ], - "content-hash": "49c99b802ca3844352e1b20ba409ea26", - "packages": [], - "packages-dev": [ - { - "name": "symfony/deprecation-contracts", - "version": "v2.4.0", - "source": { - "type": "git", - "url": "https://github.com/symfony/deprecation-contracts.git", - "reference": "5f38c8804a9e97d23e0c8d63341088cd8a22d627" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/5f38c8804a9e97d23e0c8d63341088cd8a22d627", - "reference": "5f38c8804a9e97d23e0c8d63341088cd8a22d627", - "shasum": "" - }, - "require": { - "php": ">=7.1" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-main": "2.4-dev" - }, - "thanks": { - "name": "symfony/contracts", - "url": "https://github.com/symfony/contracts" - } - }, - "autoload": { - "files": [ - "function.php" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Nicolas Grekas", - "email": "p@tchwork.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "A generic function and convention to trigger deprecation notices", - "homepage": "https://symfony.com", - "support": { - "source": "https://github.com/symfony/deprecation-contracts/tree/v2.4.0" - }, - "funding": [ - { - "url": "https://symfony.com/sponsor", - "type": "custom" - }, - { - "url": "https://github.com/fabpot", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", - "type": "tidelift" - } - ], - "time": "2021-03-23T23:28:01+00:00" - }, - { - "name": "symfony/phpunit-bridge", - "version": "v5.3.0", - "source": { - "type": "git", - "url": "https://github.com/symfony/phpunit-bridge.git", - "reference": "15cab721487b7bf43ad545a1e7d0095782e26f8c" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/phpunit-bridge/zipball/15cab721487b7bf43ad545a1e7d0095782e26f8c", - "reference": "15cab721487b7bf43ad545a1e7d0095782e26f8c", - "shasum": "" - }, - "require": { - "php": ">=7.1.3", - "symfony/deprecation-contracts": "^2.1" - }, - "conflict": { - "phpunit/phpunit": "<7.5|9.1.2" - }, - "require-dev": { - "symfony/error-handler": "^4.4|^5.0" - }, - "suggest": { - "symfony/error-handler": "For tracking deprecated interfaces usages at runtime with DebugClassLoader" - }, - "bin": [ - "bin/simple-phpunit" - ], - "type": "symfony-bridge", - "extra": { - "thanks": { - "name": "phpunit/phpunit", - "url": "https://github.com/sebastianbergmann/phpunit" - } - }, - "autoload": { - "files": [ - "bootstrap.php" - ], - "psr-4": { - "Symfony\\Bridge\\PhpUnit\\": "" - }, - "exclude-from-classmap": [ - "/Tests/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Nicolas Grekas", - "email": "p@tchwork.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Provides utilities for PHPUnit, especially user deprecation notices management", - "homepage": "https://symfony.com", - "support": { - "source": "https://github.com/symfony/phpunit-bridge/tree/v5.3.0" - }, - "funding": [ - { - "url": "https://symfony.com/sponsor", - "type": "custom" - }, - { - "url": "https://github.com/fabpot", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", - "type": "tidelift" - } - ], - "time": "2021-05-26T17:57:12+00:00" - } - ], - "aliases": [], - "minimum-stability": "stable", - "stability-flags": [], - "prefer-stable": false, - "prefer-lowest": false, - "platform": { - "php": "^7.1|^8.0" - }, - "platform-dev": [], - "plugin-api-version": "2.0.0" -} diff --git a/rector.php b/rector.php new file mode 100644 index 0000000..49b2be2 --- /dev/null +++ b/rector.php @@ -0,0 +1,16 @@ +withPaths([ + __DIR__ . '/spoon', + ]) + // uncomment to reach your current PHP version + ->withPhpSets(php85: true) + ->withTypeCoverageLevel(0) + ->withDeadCodeLevel(0) + ->withCodeQualityLevel(0); diff --git a/spoon/CHANGELOG b/spoon/CHANGELOG index fcf5ccd..408e44a 100644 --- a/spoon/CHANGELOG +++ b/spoon/CHANGELOG @@ -1,3 +1,11 @@ +2.0.0 (2025-xx-xx) +--- +- Upgrade to PHP 8.5 +- The default value for SpoonFilter::getValue parameter defaultValue is now null +- E_STRICT is no longer supported +- Replaced PDO::MYSQL_ATTR_USE_BUFFERED_QUERY with Pdo\Mysql::ATTR_USE_BUFFERED_QUERY (deprecated in PHP 8.5) +- Removed curl_close, as it does nothing since PHP 8.0 (deprecated in PHP 8.5) + 1.3.5 (xxxx-xx-xx) ---- Bugfixes: diff --git a/spoon/database/database.php b/spoon/database/database.php index 98e8ada..4e0b7ad 100644 --- a/spoon/database/database.php +++ b/spoon/database/database.php @@ -92,7 +92,7 @@ class SpoonDatabase * * @var array */ - private $queries = array(); + private $queries = []; /** @@ -169,11 +169,11 @@ private function connect() // mysql only option if($this->driver == 'mysql') { - $this->handler->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true); + $this->handler->setAttribute(Pdo\Mysql::ATTR_USE_BUFFERED_QUERY, true); } } - catch(PDOException $e) + catch(PDOException) { throw new SpoonDatabaseException('A database connection could not be established.', 0, $this->password); } @@ -189,7 +189,7 @@ private function connect() * @param string[optional] $where The WHERE-clause. * @param mixed[optional] $parameters The parameters that will be used in the query. */ - public function delete($table, $where = null, $parameters = array()) + public function delete($table, $where = null, $parameters = []) { // create connection if(!$this->handler) $this->connect(); @@ -234,7 +234,7 @@ public function delete($table, $where = null, $parameters = array()) } // debug enabled - if($this->debug) $this->queries[] = array('query' => $query, 'parameters' => $parameters); + if($this->debug) $this->queries[] = ['query' => $query, 'parameters' => $parameters]; // number of affected rows return (int) $statement->rowCount(); @@ -248,7 +248,7 @@ public function delete($table, $where = null, $parameters = array()) */ public function drop($tables) { - $this->execute('DROP TABLE ' . implode(', ', array_map(array($this, 'quoteName'), (array) $tables))); + $this->execute('DROP TABLE ' . implode(', ', array_map($this->quoteName(...), (array) $tables))); } @@ -258,7 +258,7 @@ public function drop($tables) * @param string $query The query to execute, only use with queries that don't return a result. * @param mixed[optional] $parameters The parameters that will be used in the query. */ - public function execute($query, $parameters = array()) + public function execute($query, $parameters = []) { // create connection if(!$this->handler) $this->connect(); @@ -298,7 +298,7 @@ public function execute($query, $parameters = array()) } // debug enabled - if($this->debug) $this->queries[] = array('query' => $query, 'parameters' => $parameters); + if($this->debug) $this->queries[] = ['query' => $query, 'parameters' => $parameters]; } @@ -309,7 +309,7 @@ public function execute($query, $parameters = array()) * @param string $query The query, specify maximum one field in the SELECT-statement. * @param mixed[optional] $parameters The parameters that will be used in the query. */ - public function getColumn($query, $parameters = array()) + public function getColumn($query, $parameters = []) { // create connection if(!$this->handler) $this->connect(); @@ -349,7 +349,7 @@ public function getColumn($query, $parameters = array()) } // debug enabled - if($this->debug) $this->queries[] = array('query' => $query, 'parameters' => $parameters); + if($this->debug) $this->queries[] = ['query' => $query, 'parameters' => $parameters]; // retrieve column data return $statement->fetchAll(PDO::FETCH_COLUMN); @@ -411,10 +411,10 @@ public function getEnumValues($table, $field) if(!isset($row['Type'])) throw new SpoonDatabaseException('There is no type information available about this field', 0, $this->password); // has a type but it's not an enum - if(strtolower(substr($row['Type'], 0, 4) != 'enum')) throw new SpoonDatabaseException('This field "' . $field . '" is not an enum field.', 0, $this->password); + if(strtolower(!str_starts_with($row['Type'], 'enum'))) throw new SpoonDatabaseException('This field "' . $field . '" is not an enum field.', 0, $this->password); // process values - $aSearch = array('enum', '(', ')', '\''); + $aSearch = ['enum', '(', ')', '\'']; $types = str_replace($aSearch, '', $row['Type']); // return @@ -451,7 +451,7 @@ public function getHostname() * @param string $query Teh query to perform. * @param mixed[optional] $parameters The parameters that will be used in the query. */ - public function getNumRows($query, $parameters = array()) + public function getNumRows($query, $parameters = []) { // create connection if(!$this->handler) $this->connect(); @@ -491,7 +491,7 @@ public function getNumRows($query, $parameters = array()) } // debug enabled - if($this->debug) $this->queries[] = array('query' => $query, 'parameters' => $parameters); + if($this->debug) $this->queries[] = ['query' => $query, 'parameters' => $parameters]; // number of results return $statement->rowCount(); @@ -505,7 +505,7 @@ public function getNumRows($query, $parameters = array()) * @param string $query The query to perform. * @param mixed[optional] $parameters The parameters that will be used in the query. */ - public function getPairs($query, $parameters = array()) + public function getPairs($query, $parameters = []) { // create connection if(!$this->handler) $this->connect(); @@ -515,7 +515,7 @@ public function getPairs($query, $parameters = array()) $parameters = (array) $parameters; // init var - $results = array(); + $results = []; $keys = null; // fetch results @@ -571,7 +571,7 @@ public function getQueries() * @param string $query The query to perform. If multiple rows are selected only the first row will be returned. * @param mixed[optional] $parameters The parameters that will be used in the query. */ - public function getRecord($query, $parameters = array()) + public function getRecord($query, $parameters = []) { // create connection if(!$this->handler) $this->connect(); @@ -611,7 +611,7 @@ public function getRecord($query, $parameters = array()) } // debug enabled - if($this->debug) $this->queries[] = array('query' => $query, 'parameters' => $parameters); + if($this->debug) $this->queries[] = ['query' => $query, 'parameters' => $parameters]; // fetch the keys $aRecord = $statement->fetch(PDO::FETCH_ASSOC); @@ -629,7 +629,7 @@ public function getRecord($query, $parameters = array()) * @param mixed[optional] $parameters The parameters that will be used in the query. * @param string[optional] $key The field that should be used as key, make sure this is unique for each row. */ - public function getRecords($query, $parameters = array(), $key = null) + public function getRecords($query, $parameters = [], $key = null) { // create connection if(!$this->handler) $this->connect(); @@ -669,7 +669,7 @@ public function getRecords($query, $parameters = array(), $key = null) } // debug enabled - if($this->debug) $this->queries[] = array('query' => $query, 'parameters' => $parameters); + if($this->debug) $this->queries[] = ['query' => $query, 'parameters' => $parameters]; // fetch the keys $aRecords = (array) $statement->fetchAll(PDO::FETCH_ASSOC); @@ -685,7 +685,7 @@ public function getRecords($query, $parameters = array(), $key = null) } // data or no data - return (isset($aData)) ? $aData : null; + return $aData ?? null; } // has results @@ -746,7 +746,7 @@ public function getUsername() * @param string $query The query to perform. * @param mixed[optional] $parameters The parameters that will be used in the query. */ - public function getVar($query, $parameters = array()) + public function getVar($query, $parameters = []) { // create connection if(!$this->handler) $this->connect(); @@ -786,7 +786,7 @@ public function getVar($query, $parameters = array()) } // debug enabled - if($this->debug) $this->queries[] = array('query' => $query, 'parameters' => $parameters); + if($this->debug) $this->queries[] = ['query' => $query, 'parameters' => $parameters]; // fetch the var return $statement->fetchColumn(); @@ -812,7 +812,7 @@ public function insert($table, array $values) $query = 'INSERT INTO ' . $this->quoteName((string) $table) . ' ('; $keys = array_keys($values); $actualValues = array_values($values); - $parameters = array(); + $parameters = []; // multidimensional array if(is_array($actualValues[0])) @@ -825,7 +825,7 @@ public function insert($table, array $values) $subKeys = array_keys($actualValues[0]); // prefix with table name - array_walk($subKeys, array($this, 'prefixTableNames'), $table); + array_walk($subKeys, $this->prefixTableNames(...), $table); // build query $query .= implode(', ', $subKeys) . ') VALUES '; @@ -882,7 +882,7 @@ public function insert($table, array $values) $numFields = count($actualValues); // prefix with table name - array_walk($keys, array($this, 'prefixTableNames'), $table); + array_walk($keys, $this->prefixTableNames(...), $table); // build query $query .= implode(', ', $keys) . ') VALUES ('; @@ -937,7 +937,7 @@ public function insert($table, array $values) } // debug enabled - if($this->debug) $this->queries[] = array('query' => $query, 'parameters' => $parameters); + if($this->debug) $this->queries[] = ['query' => $query, 'parameters' => $parameters]; // fetch the keys return (int) $this->handler->lastInsertId(); @@ -955,7 +955,7 @@ public function optimize($tables) $tables = (func_num_args() == 1) ? (array) $tables : func_get_args(); // build & execute query - return $this->getRecords('OPTIMIZE TABLE ' . implode(', ', array_map(array($this, 'quoteName'), $tables))); + return $this->getRecords('OPTIMIZE TABLE ' . implode(', ', array_map($this->quoteName(...), $tables))); } @@ -995,7 +995,7 @@ protected function quoteName($name) * @param mixed[optional] $parameters The parameters that will be used in the query. * @param string[optional] $key The field that should be used as key, make sure this is unique for each row. */ - public function retrieve($query, $parameters = array(), $key = null) + public function retrieve($query, $parameters = [], $key = null) { return $this->getRecords($query, $parameters, $key); } @@ -1120,7 +1120,7 @@ public function truncate($tables) * @param string[optional] $where The WHERE-clause. * @param mixed[optional] $parameters The parameters that will be used in the query. */ - public function update($table, array $values, $where = null, $parameters = array()) + public function update($table, array $values, $where = null, $parameters = []) { // create connection if(!$this->handler) $this->connect(); @@ -1145,7 +1145,7 @@ public function update($table, array $values, $where = null, $parameters = array foreach($parameters as $key => $value) { // key such as ':id' starting - if(substr($key, 0, 1) == ':') + if(str_starts_with((string) $key, ':')) { $namedParameters = true; break; @@ -1223,7 +1223,7 @@ public function update($table, array $values, $where = null, $parameters = array } // debug enabled - if($this->debug) $this->queries[] = array('query' => $query, 'parameters' => $parameters); + if($this->debug) $this->queries[] = ['query' => $query, 'parameters' => $parameters]; // number of results return (int) $statement->rowCount(); diff --git a/spoon/datagrid/column.php b/spoon/datagrid/column.php index d6155f6..4a5c430 100644 --- a/spoon/datagrid/column.php +++ b/spoon/datagrid/column.php @@ -33,7 +33,7 @@ class SpoonDatagridColumn * * @var array */ - private $attributes = array('general' => array(), 'header' => array()); + private $attributes = ['general' => [], 'header' => []]; /** @@ -189,7 +189,7 @@ public function __construct($name, $label = null, $value = null, $URL = null, $t */ public function clearAttributes() { - $this->attributes['general'] = array(); + $this->attributes['general'] = []; } @@ -489,7 +489,7 @@ public function setSorting($on = true) */ public function setSortingMethod($sort = 'asc') { - $this->sortingMethod = SpoonFilter::getValue($sort, array('asc', 'desc'), 'asc'); + $this->sortingMethod = SpoonFilter::getValue($sort, ['asc', 'desc'], 'asc'); } diff --git a/spoon/datagrid/datagrid.php b/spoon/datagrid/datagrid.php index 763b49f..54ca34f 100644 --- a/spoon/datagrid/datagrid.php +++ b/spoon/datagrid/datagrid.php @@ -32,7 +32,7 @@ class SpoonDataGrid * * @var array */ - private $allowedSortingColumns = array(); + private $allowedSortingColumns = []; /** @@ -40,11 +40,11 @@ class SpoonDataGrid * * @var array */ - private $attributes = array('datagrid' => array(), - 'row' => array(), - 'row_even' => array(), - 'row_odd' => array(), - 'footer' => array()); + private $attributes = ['datagrid' => [], + 'row' => [], + 'row_even' => [], + 'row_odd' => [], + 'footer' => []]; /** @@ -60,7 +60,7 @@ class SpoonDataGrid * * @var array */ - private $columnFunctions = array(); + private $columnFunctions = []; /** @@ -68,7 +68,7 @@ class SpoonDataGrid * * @var array */ - protected $columns = array(); + protected $columns = []; /** @@ -130,7 +130,7 @@ class SpoonDataGrid /** * Class used to define paging * - * @var SpoonDataGridPaging + * @var string */ private $pagingClass = 'SpoonDataGridPaging'; @@ -148,7 +148,7 @@ class SpoonDataGrid * * @var array */ - private $rowFunctions = array(); + private $rowFunctions = []; /** @@ -156,7 +156,7 @@ class SpoonDataGrid * * @var string */ - private $rowFunctionsParsed = array(); + private $rowFunctionsParsed = []; /** @@ -172,7 +172,7 @@ class SpoonDataGrid * * @var array */ - private $sortingColumns = array(); + private $sortingColumns = []; /** @@ -180,10 +180,12 @@ class SpoonDataGrid * * @var array */ - private $sortingIcons = array( 'asc' => null, - 'ascSelected' => null, - 'desc' => null, - 'descSelected' => null); + private $sortingIcons = [ + 'asc' => null, + 'ascSelected' => null, + 'desc' => null, + 'descSelected' => null, + ]; /** @@ -191,10 +193,12 @@ class SpoonDataGrid * * @var array */ - private $sortingLabels = array( 'asc' => 'Sort ascending', - 'ascSelected' => 'Sorted ascending', - 'desc' => 'Sort descending', - 'descSelected' => 'Sorted descending'); + private $sortingLabels = [ + 'asc' => 'Sort ascending', + 'ascSelected' => 'Sorted ascending', + 'desc' => 'Sort descending', + 'descSelected' => 'Sorted descending', + ]; /** @@ -293,7 +297,7 @@ public function addColumn($name, $label = null, $value = null, $URL = null, $tit $this->columns[$name] = new SpoonDatagridColumn($name, $label, $value, $URL, $title, $image, $sequence); // add the class as an attribute to this column - $this->columns[$name]->setAttributes(array('class' => $name)); + $this->columns[$name]->setAttributes(['class' => $name]); } @@ -307,7 +311,7 @@ public function addColumn($name, $label = null, $value = null, $URL = null, $tit */ private function buildURL($offset, $order, $sort) { - return str_replace(array('[offset]', '[order]', '[sort]'), array($offset, $order, $sort), $this->URL); + return str_replace(['[offset]', '[order]', '[sort]'], [$offset, $order, $sort], $this->URL); } @@ -316,7 +320,7 @@ private function buildURL($offset, $order, $sort) */ public function clearAttributes() { - $this->attributes['datagrid'] = array(); + $this->attributes['datagrid'] = []; } @@ -344,7 +348,7 @@ public function clearColumnAttributes($column) */ public function clearEvenRowAttributes() { - $this->attributes['row_even'] = array(); + $this->attributes['row_even'] = []; } @@ -353,7 +357,7 @@ public function clearEvenRowAttributes() */ public function clearOddRowAttributes() { - $this->attributes['row_odd'] = array(); + $this->attributes['row_odd'] = []; } @@ -362,7 +366,7 @@ public function clearOddRowAttributes() */ public function clearRowAttributes() { - $this->attributes['row'] = array(); + $this->attributes['row'] = []; } @@ -381,7 +385,7 @@ private function createColumns() $this->addColumn($column, $column, '[' . $column . ']', null, null, null, (count($this->columns) +1)); // by default the column name will be added as a class - $this->columns[$column]->setAttributes(array('class' => $column)); + $this->columns[$column]->setAttributes(['class' => $column]); // may be sorted on $this->allowedSortingColumns[] = $column; @@ -393,7 +397,7 @@ private function createColumns() /** * Shows the output & stops script execution. */ - public function display() + public function display(): never { echo $this->getContent(); exit; @@ -406,7 +410,7 @@ public function display() private function generateOrder() { // delete current cache of sortable columns - $this->sortingColumns = array(); + $this->sortingColumns = []; // columns present if(count($this->columns) != 0) @@ -484,7 +488,7 @@ public function getColumns() private function getColumnsSequence() { // init var - $columns = array(); + $columns = []; // loop all the columns foreach($this->columns as $column) $columns[$column->getSequence()] = $column->getName(); @@ -526,7 +530,7 @@ public function getDebug() * @return string * @param array[optional] $array The attributes to be converted into HTML-attributes. */ - private function getHTMLAttributes(array $array = array()) + private function getHTMLAttributes(array $array = []) { // output $html = ''; @@ -662,13 +666,13 @@ public function getPagingLimit() public function getSort() { // default sort - $sort = ($this->sortParameter !== null) ? $this->sortParameter : null; + $sort = $this->sortParameter ?? null; // redefine $sort = (isset($_GET['sort'])) ? (string) $_GET['sort'] : $sort; // retrieve sort - return SpoonFilter::getValue($sort, array('asc', 'desc'), 'asc'); + return SpoonFilter::getValue($sort, ['asc', 'desc'], 'asc'); } @@ -716,7 +720,7 @@ public function getTemplate() */ private function getTemplatePath() { - return ($this->template != null) ? $this->template : dirname(__FILE__) . '/datagrid.tpl'; + return ($this->template != null) ? $this->template : __DIR__ . '/datagrid.tpl'; } @@ -746,7 +750,7 @@ private function parse() if(count($aRecords) != 0) { // compile directory - $compileDirectory = ($this->compileDirectory !== null) ? $this->compileDirectory : dirname(realpath(__FILE__)); + $compileDirectory = $this->compileDirectory ?? dirname(realpath(__FILE__)); $this->tpl->setCompileDirectory($compileDirectory); // only force compiling when debug is enabled @@ -799,7 +803,7 @@ private function parseAttributes() private function parseBody(array $records) { // init var - $rows = array(); + $rows = []; // columns sequence $sequence = $this->getColumnsSequence(); @@ -817,7 +821,7 @@ private function parseBody(array $records) $this->parseRowFunctions($record, $this->attributes['row']); // reset row - $row = array('attributes' => '', 'columns' => array()); + $row = ['attributes' => '', 'columns' => []]; // row attributes $row['attributes'] = str_replace($record['labels'], $record['values'], $this->getHtmlAttributes($this->attributes['row'])); @@ -829,7 +833,7 @@ private function parseBody(array $records) $row['attributes'] = str_replace($record['labels'], $record['values'], $this->getHtmlAttributes($this->rowFunctionsParsed)); // clear for the next row - $this->rowFunctionsParsed = array(); + $this->rowFunctionsParsed = []; } // default row behaviour @@ -844,8 +848,8 @@ private function parseBody(array $records) // no longer overwrite default attributes with odd/even attributes. if(!empty($row['attributes'])) { - $cycleData = array(); - $rowData = array(); + $cycleData = []; + $rowData = []; preg_match_all('/( (.*?)=\"(.*?)\")/', $row['attributes'], $rowData); preg_match_all('/( (.*?)=\"(.*?)\")/', $cycleAttributes, $cycleData); @@ -873,7 +877,7 @@ private function parseBody(array $records) else $row['attributes'] = $cycleAttributes; // define the columns - $columns = array(); + $columns = []; // loop columns foreach($sequence as $name) @@ -965,7 +969,7 @@ private function parseBody(array $records) if(!$column->getHidden()) { // add this column - $columns[] = array('attributes' => $columnAttributes, 'value' => $columnValue); + $columns[] = ['attributes' => $columnAttributes, 'value' => $columnValue]; // add to custom list $row['column'][$name] = $columnValue; @@ -1116,7 +1120,7 @@ private function parseFooter() private function parseHeader() { // init vars - $header = array(); + $header = []; // sequence $sequence = $this->getColumnsSequence(); @@ -1125,14 +1129,14 @@ private function parseHeader() $sorting = $this->getSorting(); // sortable columns - $sortingColumns = array(); + $sortingColumns = []; foreach($sequence as $oColumn) if($this->columns[$oColumn]->getSorting()) $sortingColumns[] = $oColumn; // loop columns foreach($sequence as $name) { // define column - $column = array(); + $column = []; // column $oColumn = $this->columns[$name]; @@ -1266,7 +1270,7 @@ private function parsePaging() if($this->paging) { // offset, order & sort - $this->tpl->assign(array('offset', 'order', 'sort'), array($this->getOffset(), $this->getOrder(), $this->getSort())); + $this->tpl->assign(['offset', 'order', 'sort'], [$this->getOffset(), $this->getOrder(), $this->getSort()]); // number of results $this->tpl->assign('iResults', $this->source->getNumResults()); @@ -1281,7 +1285,7 @@ private function parsePaging() $this->tpl->assign('iPerPage', $this->pagingLimit); // parse paging - $content = call_user_func(array($this->pagingClass, 'getContent'), $this->URL, $this->getOffset(), $this->getOrder(), $this->getSort(), $this->source->getNumResults(), $this->pagingLimit, $this->debug, $this->compileDirectory); + $content = call_user_func([$this->pagingClass, 'getContent'], $this->URL, $this->getOffset(), $this->getOrder(), $this->getSort(), $this->source->getNumResults(), $this->pagingLimit, $this->debug, $this->compileDirectory); // asign content $this->tpl->assign('paging', $content); @@ -1298,7 +1302,7 @@ private function parsePaging() private function parseRecord(array $record) { // init var - $array = array('labels' => array(), 'values' => array()); + $array = ['labels' => [], 'values' => []]; // create labels/values array foreach($record as $label => $value) @@ -1346,7 +1350,7 @@ private function parseRecord(array $record) * @param array $record The row-data. * @param array[optional] $rowAttributes The attributes on the row. */ - private function parseRowFunctions($record, array $rowAttributes = null) + private function parseRowFunctions($record, ?array $rowAttributes = null) { // store old error reporting settings $currentErrorReporting = ini_get('error_reporting'); @@ -1484,8 +1488,14 @@ public function setColumnFunction($function, $arguments = null, $columns = null, // has results if($this->source->getNumResults() > 0) { + if (is_object($function)) { + if (!is_callable($function)) { + throw new SpoonDatagridException('The object "' . $function::class . '" is not callable.'); + } + } + // regular function - if(!is_array($function)) + else if(!is_array($function)) { // function checks if(!function_exists((string) $function)) throw new SpoonDatagridException('The function "' . (string) $function . '" doesn\'t exist.'); @@ -1498,11 +1508,11 @@ public function setColumnFunction($function, $arguments = null, $columns = null, if(count($function) != 2) throw new SpoonDatagridException('When providing a method for a column function it must be like array(\'class\', \'method\')'); // method doesn't exist - elseif(!is_callable(array($function[0], $function[1]))) throw new SpoonDatagridException('The method ' . (string) $function[0] . '::' . (string) $function[1] . ' does not exist.'); + elseif(!is_callable([$function[0], $function[1]])) throw new SpoonDatagridException('The method ' . (string) $function[0] . '::' . (string) $function[1] . ' does not exist.'); } // add to function stack - $this->columnFunctions[] = array('function' => $function, 'arguments' => $arguments, 'columns' => $columns, 'overwrite' => (bool) $overwrite); + $this->columnFunctions[] = ['function' => $function, 'arguments' => $arguments, 'columns' => $columns, 'overwrite' => (bool) $overwrite]; } } @@ -1601,7 +1611,7 @@ public function setColumnsSequence($columns) if($this->source->getNumResults() > 0) { // array - if(is_array($columns)) call_user_func_array(array($this, 'setColumnsSequence'), $columns); + if(is_array($columns)) array_walk($columns, $this->setColumnsSequence(...)); // multiple arguments else @@ -1841,8 +1851,14 @@ public function setRowFunction($function, $arguments = null, $overwrite = false) // has results if($this->source->getNumResults() > 0) { + if (is_object($function)) { + if (!is_callable($function)) { + throw new SpoonDatagridException('The object "' . $function::class . '" is not callable.'); + } + } + // regular function - if(!is_array($function)) + else if(!is_array($function)) { // function checks if(!function_exists((string) $function)) throw new SpoonDatagridException('The function "' . (string) $function . '" doesn\'t exist.'); @@ -1855,11 +1871,11 @@ public function setRowFunction($function, $arguments = null, $overwrite = false) if(count($function) != 2) throw new SpoonDatagridException('When providing a method for a column function it must be like array(\'class\', \'method\')'); // method doesn't exist - elseif(!is_callable(array($function[0], $function[1]))) throw new SpoonDatagridException('The method ' . (string) $function[0] . '::' . (string) $function[1] . ' does not exist.'); + elseif(!is_callable([$function[0], $function[1]])) throw new SpoonDatagridException('The method ' . (string) $function[0] . '::' . (string) $function[1] . ' does not exist.'); } // add to function stack - $this->rowFunctions[] = array('function' => $function, 'arguments' => $arguments, 'overwrite' => (bool) $overwrite); + $this->rowFunctions[] = ['function' => $function, 'arguments' => $arguments, 'overwrite' => (bool) $overwrite]; } } @@ -1952,7 +1968,7 @@ public function setSortingLabels($asc = null, $ascSelected = null, $desc = null, */ public function setSortParameter($value = 'desc') { - $this->sortParameter = SpoonFilter::getValue($value, array('asc', 'desc'), 'asc'); + $this->sortParameter = SpoonFilter::getValue($value, ['asc', 'desc'], 'asc'); } diff --git a/spoon/datagrid/paging.php b/spoon/datagrid/paging.php index f9dc12d..b79d757 100644 --- a/spoon/datagrid/paging.php +++ b/spoon/datagrid/paging.php @@ -98,7 +98,7 @@ public static function getContent($URL, $offset, $order, $sort, $numResults, $nu // compile directory if($compileDirectory !== null) $tpl->setCompileDirectory($compileDirectory); - else $tpl->setCompileDirectory(dirname(__FILE__)); + else $tpl->setCompileDirectory(__DIR__); // force compiling $tpl->setForceCompile((bool) $debug); @@ -108,7 +108,7 @@ public static function getContent($URL, $offset, $order, $sort, $numResults, $nu { // label & url $previousLabel = self::$previous; - $previousURL = str_replace(array('[offset]', '[order]', '[sort]'), array(($offset - $numPerPage), $order, $sort), $URL); + $previousURL = str_replace(['[offset]', '[order]', '[sort]'], [($offset - $numPerPage), $order, $sort], $URL); $tpl->assign('previousLabel', $previousLabel); $tpl->assign('previousURL', $previousURL); } @@ -118,7 +118,7 @@ public static function getContent($URL, $offset, $order, $sort, $numResults, $nu { // label & url $nextLabel = self::$next; - $nextURL = str_replace(array('[offset]', '[order]', '[sort]'), array(($offset + $numPerPage), $order, $sort), $URL); + $nextURL = str_replace(['[offset]', '[order]', '[sort]'], [($offset + $numPerPage), $order, $sort], $URL); $tpl->assign('nextLabel', $nextLabel); $tpl->assign('nextURL', $nextURL); } @@ -126,7 +126,7 @@ public static function getContent($URL, $offset, $order, $sort, $numResults, $nu // limit $limit = 7; $breakpoint = 4; - $items = array(); + $items = []; /** * Less than or 7 pages. We know all the keys, and we put them in the array @@ -188,7 +188,7 @@ public static function getContent($URL, $offset, $order, $sort, $numResults, $nu } // init var - $pages = array(); + $pages = []; // loop pages foreach($items as $item) @@ -223,7 +223,7 @@ public static function getContent($URL, $offset, $order, $sort, $numResults, $nu $pages[$i]['otherPage'] = true; // url to this page - $pages[$i]['url'] = str_replace(array('[offset]', '[order]', '[sort]'), array((($numPerPage * $item) - $numPerPage), $order, $sort), $URL); + $pages[$i]['url'] = str_replace(['[offset]', '[order]', '[sort]'], [(($numPerPage * $item) - $numPerPage), $order, $sort], $URL); } } @@ -239,7 +239,7 @@ public static function getContent($URL, $offset, $order, $sort, $numResults, $nu // cough it up ob_start(); - $tpl->display(dirname(__FILE__) . '/paging.tpl'); + $tpl->display(__DIR__ . '/paging.tpl'); return ob_get_clean(); } } diff --git a/spoon/datagrid/source.php b/spoon/datagrid/source.php index e2c898e..baa3eee 100644 --- a/spoon/datagrid/source.php +++ b/spoon/datagrid/source.php @@ -32,7 +32,7 @@ class SpoonDatagridSource * * @var array */ - protected $data = array(); + protected $data = []; /** diff --git a/spoon/datagrid/source_array.php b/spoon/datagrid/source_array.php index 7475eed..2980f48 100644 --- a/spoon/datagrid/source_array.php +++ b/spoon/datagrid/source_array.php @@ -101,7 +101,7 @@ public function getData($offset = null, $limit = null, $order = null, $sort = nu self::$order = $order; // apply sorting - uasort($this->data, array('SpoonDataGridSourceArray', 'applySorting')); + uasort($this->data, ['SpoonDataGridSourceArray', 'applySorting']); // reverse if needed? if($sort !== null && $sort == 'desc') $this->data = array_reverse($this->data, true); diff --git a/spoon/datagrid/source_db.php b/spoon/datagrid/source_db.php index a71af2e..f7d2984 100644 --- a/spoon/datagrid/source_db.php +++ b/spoon/datagrid/source_db.php @@ -27,14 +27,6 @@ */ class SpoonDatagridSourceDB extends SpoonDatagridSource { - /** - * SpoonDatabase instance - * - * @var SpoonDatabase - */ - private $db; - - /** * Query to calculate the number of results * @@ -48,7 +40,7 @@ class SpoonDatagridSourceDB extends SpoonDatagridSource * * @var array */ - private $numResultsQueryParameters = array(); + private $numResultsQueryParameters = []; /** @@ -64,21 +56,18 @@ class SpoonDatagridSourceDB extends SpoonDatagridSource * * @var array */ - private $queryParameters = array(); + private $queryParameters = []; /** * Class construtor. * - * @param SpoonDatabase $dbConnection The database connection. + * @param SpoonDatabase $db The database connection. * @param string|array $query The query to execute. * @param string[optional] $numResultsQuery The query to use to retrieve the number of results. */ - public function __construct(SpoonDatabase $dbConnection, $query, $numResultsQuery = null) + public function __construct(private readonly SpoonDatabase $db, $query, $numResultsQuery = null) { - // database connection - $this->db = $dbConnection; - // set queries $this->setQuery($query, $numResultsQuery); } @@ -95,16 +84,10 @@ public function getColumns() if($this->numResults != 0) { // build query - switch($this->db->getDriver()) - { - case 'mysql': - $query = (substr_count($this->query, 'LIMIT ') > 0) ? $this->query : $this->query . ' LIMIT 1'; - break; - - default: - throw new SpoonDataGridException('No datagrid support has been written for this database backend (' . $this->db->getDriver() . ')'); - break; - } + $query = match ($this->db->getDriver()) { + 'mysql' => (substr_count($this->query, 'LIMIT ') > 0) ? $this->query : $this->query . ' LIMIT 1', + default => throw new SpoonDataGridException('No datagrid support has been written for this database backend (' . $this->db->getDriver() . ')'), + }; // fetch record $record = $this->db->getRecord($query, $this->queryParameters); diff --git a/spoon/date/date.php b/spoon/date/date.php index a334a48..ece5463 100644 --- a/spoon/date/date.php +++ b/spoon/date/date.php @@ -27,7 +27,7 @@ */ class SpoonDate { - protected static $locales = array(); + protected static $locales = []; /** * An alias for php's date function that makes weekdays and months language dependant. @@ -52,8 +52,8 @@ public static function getDate($format, $timestamp = null, $language = 'en', $GM if($language != 'en') { // weekdays (short & long) - $date = str_replace(array('Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'), SpoonLocale::getWeekDays($language), $date); - $abbreviatedDaysRegexes = array( + $date = str_replace(['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'], SpoonLocale::getWeekDays($language), $date); + $abbreviatedDaysRegexes = [ '/\bMon\b/', '/\bTue\b/', '/\bWed\b/', @@ -61,12 +61,12 @@ public static function getDate($format, $timestamp = null, $language = 'en', $GM '/\bFri\b/', '/\bSat\b/', '/\bSun\b/', - ); + ]; $date = preg_replace($abbreviatedDaysRegexes, SpoonLocale::getWeekDays($language, true), $date); // months (short & long) - $date = str_replace(array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'), SpoonLocale::getMonths($language), $date); - $date = str_replace(array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'), SpoonLocale::getMonths($language, true), $date); + $date = str_replace(['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'], SpoonLocale::getMonths($language), $date); + $date = str_replace(['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'], SpoonLocale::getMonths($language, true), $date); } return $date; @@ -86,7 +86,7 @@ public static function getTimeAgo($timestamp, $language = 'en', $format = null) // init vars $timestamp = (int) $timestamp; $language = SpoonFilter::getValue($language, SpoonLocale::getAvailableLanguages(), 'en', 'string'); - $locale = array(); + $locale = []; // fetch language if(!isset(self::$locales[$language])) diff --git a/spoon/directory/directory.php b/spoon/directory/directory.php index 7f588a6..9d96b38 100644 --- a/spoon/directory/directory.php +++ b/spoon/directory/directory.php @@ -216,7 +216,7 @@ public static function exists($directory) * @param array[optional] $excluded An array containing directories/files to exclude. * @param string[optional] $includeRegexp An regular expression that represents the directories/files to include in the list. Other directories will be excluded. */ - public static function getList($path, $showFiles = false, array $excluded = null, $includeRegexp = null) + public static function getList($path, $showFiles = false, ?array $excluded = null, $includeRegexp = null) { // redefine arguments $path = (string) $path; @@ -233,7 +233,7 @@ public static function getList($path, $showFiles = false, array $excluded = null } // define file list - $directories = array(); + $directories = []; // directory exists if(self::exists($path)) @@ -261,7 +261,7 @@ public static function getList($path, $showFiles = false, array $excluded = null if($includeRegexp !== null) { // init var - $matches = array(); + $matches = []; // is this a match? if(preg_match($includeRegexp, $file, $matches) != 0) $directories[] = $file; @@ -278,7 +278,7 @@ public static function getList($path, $showFiles = false, array $excluded = null if($includeRegexp !== null) { // init var - $matches = array(); + $matches = []; // is this a match? if(preg_match($includeRegexp, $file, $matches) != 0) $directories[] = $file; diff --git a/spoon/exception/exception.php b/spoon/exception/exception.php index 312d92d..bbd0378 100644 --- a/spoon/exception/exception.php +++ b/spoon/exception/exception.php @@ -53,7 +53,7 @@ public function __construct($message, $code = 0, $obfuscate = null) parent::__construct((string) $message, (int) $code); // set name - $this->name = get_class($this); + $this->name = static::class; // obfuscating? if ($obfuscate !== null) { @@ -84,7 +84,7 @@ public function getObfuscate() // Redefine the exception handler if we are not running in the command line. if (!Spoon::inCli()) { - set_exception_handler('exceptionHandler'); + set_exception_handler(exceptionHandler(...)); } /** @@ -99,7 +99,7 @@ function exceptionHandler($exception) $trace = $exception->getTrace(); // specific name - $name = (method_exists($exception, 'getName')) ? $exception->getName() : get_class($exception); + $name = (method_exists($exception, 'getName')) ? $exception->getName() : $exception::class; // spoon type exception if (method_exists($exception, 'getName') && strtolower(substr($exception->getName(), 0, 5)) == 'spoon' && $exception->getCode() != 0) { @@ -118,7 +118,7 @@ function exceptionHandler($exception) } // user agent - $userAgent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '(Unknown)'; + $userAgent = $_SERVER['HTTP_USER_AGENT'] ?? '(Unknown)'; // custom callback? if (Spoon::getExceptionCallback() != '') { @@ -170,7 +170,7 @@ function exceptionHandler($exception) $headers .= "From: Spoon Library \n"; // send email - @mail(Spoon::getDebugEmail(), 'Exception Occured', getOutput($exception), $headers); + @mail(Spoon::getDebugEmail(), 'Exception Occured', (string) getOutput($exception), $headers); } // stop script execution @@ -180,8 +180,8 @@ function exceptionHandler($exception) function getOutput($exception) { // specific name - $name = (method_exists($exception, 'getName')) ? $exception->getName() : get_class($exception); - $userAgent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '(Unknown)'; + $name = (method_exists($exception, 'getName')) ? $exception->getName() : $exception::class; + $userAgent = $_SERVER['HTTP_USER_AGENT'] ?? '(Unknown)'; // generate output $output = ' @@ -292,7 +292,7 @@ function getOutput($exception) Line - ' . ((isset($traceStack['line'])) ? $traceStack['line'] : '(Unknown)') . ' + ' . ($traceStack['line'] ?? '(Unknown)') . ' '; @@ -410,9 +410,9 @@ function exceptionHandlerDumper($var) function dimCommonPathPrefix($path) { // determine the longest shared prefix - $prefix = dirname(__FILE__); + $prefix = __DIR__; while (!empty($prefix) && $prefix !== '/' && $prefix !== '.') { - if (strpos($path, $prefix . DIRECTORY_SEPARATOR) === 0) { + if (str_starts_with($path, $prefix . DIRECTORY_SEPARATOR)) { break; } $prefix = dirname($prefix); diff --git a/spoon/feed/rss.php b/spoon/feed/rss.php index 60448eb..e86d7dc 100644 --- a/spoon/feed/rss.php +++ b/spoon/feed/rss.php @@ -38,7 +38,7 @@ class SpoonFeedRSS * * @var array */ - private $categories = array(); + private $categories = []; /** @@ -94,7 +94,7 @@ class SpoonFeedRSS * * @var array */ - private $image = array(); + private $image = []; /** @@ -102,7 +102,7 @@ class SpoonFeedRSS * * @var array */ - private $items = array(); + private $items = []; /** @@ -158,7 +158,7 @@ class SpoonFeedRSS * * @var array */ - private $skipDays = array(); + private $skipDays = []; /** @@ -166,7 +166,7 @@ class SpoonFeedRSS * * @var array */ - private $skipHours = array(); + private $skipHours = []; /** @@ -217,7 +217,7 @@ class SpoonFeedRSS * @param string $description The description of the feed. * @param array[optional] $items An array with SpoonFeedRSSItems. */ - public function __construct($title, $link, $description, array $items = array()) + public function __construct($title, $link, $description, array $items = []) { // set properties $this->setTitle($title); @@ -238,7 +238,7 @@ public function __construct($title, $link, $description, array $items = array()) public function addCategory($category, $domain = null) { // init var - $categoryDetails = array(); + $categoryDetails = []; // add category $categoryDetails['category'] = (string) $category; @@ -270,7 +270,7 @@ public function addItem(SpoonFeedRSSItem $item) public function addSkipDay($day) { // allowed days - $allowedDays = array('sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saterday'); + $allowedDays = ['sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saterday']; // redefine var $day = (string) SpoonFilter::getValue(strtolower($day), $allowedDays, 'sunday'); @@ -297,7 +297,7 @@ public function addSkipHour($hour) $hour = (int) SpoonFilter::getValue($hour, $allowedHours, 0); // validate - if(!in_array($hour, $allowedHours)) throw new SpoonFeedException('This (' . $hour . ') isn\'t a valid hour. Only ' . join(', ', $allowedHours) . ' are allowed.)'); + if(!in_array($hour, $allowedHours)) throw new SpoonFeedException('This (' . $hour . ') isn\'t a valid hour. Only ' . implode(', ', $allowedHours) . ' are allowed.)'); if(in_array($hour, $this->skipHours)) throw new SpoonFeedException('This (' . $hour . ') hour is already added.'); // set property @@ -750,7 +750,7 @@ public static function isValid($URL, $type = 'url') { // redefine var $URL = (string) $URL; - $type = (string) SpoonFilter::getValue($type, array('url', 'string'), 'url'); + $type = (string) SpoonFilter::getValue($type, ['url', 'string'], 'url'); // validate if($type == 'url' && !SpoonFilter::isURL($URL)) throw new SpoonFeedException('This (' . $URL . ') isn\'t a valid url.'); @@ -843,7 +843,7 @@ public static function readFromFeed($URL, $type = 'url', $force = false) { // redefine var $URL = (string) $URL; - $type = (string) SpoonFilter::getValue($type, array('url', 'string'), 'url'); + $type = (string) SpoonFilter::getValue($type, ['url', 'string'], 'url'); // validate if($type == 'url' && !SpoonFilter::isURL($URL)) throw new SpoonFeedException('This (' . SpoonFilter::htmlentities($URL) . ') isn\'t a valid URL.'); @@ -881,7 +881,7 @@ public static function readFromFeed($URL, $type = 'url', $force = false) } // catch exceptions - catch(Exception $e) + catch(Exception) { // ignore exceptions } @@ -911,7 +911,7 @@ public static function readFromFeed($URL, $type = 'url', $force = false) } // catch exception - catch(Exception $e) + catch(Exception) { // ignore exceptions } @@ -931,7 +931,7 @@ public static function readFromFeed($URL, $type = 'url', $force = false) } // catch exception - catch(Exception $e) + catch(Exception) { // ignore exceptions } @@ -997,7 +997,7 @@ public static function readFromFeed($URL, $type = 'url', $force = false) } // catch exception - catch(Exception $e) + catch(Exception) { // ignore exceptions } @@ -1083,7 +1083,7 @@ public function setCloud($domain, $port, $path, $registerProcedure, $protocol) $this->cloud['port'] = (int) $port; $this->cloud['path'] = (string) $path; $this->cloud['register_procedure'] = (string) $registerProcedure; - $this->cloud['protocol'] = (string) SpoonFilter::getValue($protocol, array('xml-rpc', 'soap', 'http-post'), 'xml-rpc'); + $this->cloud['protocol'] = (string) SpoonFilter::getValue($protocol, ['xml-rpc', 'soap', 'http-post'], 'xml-rpc'); } @@ -1253,7 +1253,7 @@ public function setSorting($on = true) */ public function setSortingMethod($sortingMethod = 'desc') { - $aAllowedSortingMethods = array('asc', 'desc'); + $aAllowedSortingMethods = ['asc', 'desc']; // set sorting method self::$sortingMethod = SpoonFilter::getValue($sortingMethod, $aAllowedSortingMethods, 'desc'); @@ -1302,7 +1302,7 @@ private function sort() $items = $this->getItems(); // sort - uasort($items, array('SpoonFeedRSS', 'compareObjects')); + uasort($items, ['SpoonFeedRSS', 'compareObjects']); // set items $this->items = $items; diff --git a/spoon/feed/rss_item.php b/spoon/feed/rss_item.php index f354fc0..e225863 100644 --- a/spoon/feed/rss_item.php +++ b/spoon/feed/rss_item.php @@ -39,7 +39,7 @@ class SpoonFeedRSSItem * * @var array */ - private $categories = array(); + private $categories = []; /** @@ -71,7 +71,7 @@ class SpoonFeedRSSItem * * @var array */ - private $guid = array(); + private $guid = []; /** @@ -95,7 +95,7 @@ class SpoonFeedRSSItem * * @var array */ - private $source = array(); + private $source = []; /** @@ -408,7 +408,7 @@ public static function readFromXML(SimpleXMLElement $item) } // catch exceptions - catch(Exception $e) + catch(Exception) { // ignore exceptions } @@ -430,7 +430,7 @@ public static function readFromXML(SimpleXMLElement $item) } // catch exceptions - catch(Exception $e) + catch(Exception) { // ignore exceptions } @@ -451,7 +451,7 @@ public static function readFromXML(SimpleXMLElement $item) } // catch exceptions - catch(Exception $e) + catch(Exception) { // ignore exceptions } @@ -475,7 +475,7 @@ public static function readFromXML(SimpleXMLElement $item) } // catch exceptions - catch(Exception $e) + catch(Exception) { // ignore exceptions } diff --git a/spoon/file/csv.php b/spoon/file/csv.php index c50da1a..7d22e44 100644 --- a/spoon/file/csv.php +++ b/spoon/file/csv.php @@ -44,7 +44,7 @@ class SpoonFileCSV * @param string[optional] $enclosure The enclosure character of the CSV. * @param bool[optional] $download Should the file be downloaded? */ - public static function arrayToFile($path, array $array, array $columns = null, array $excludeColumns = null, $delimiter = ',', $enclosure = '"', $download = false) + public static function arrayToFile($path, array $array, ?array $columns = null, ?array $excludeColumns = null, $delimiter = ',', $enclosure = '"', $download = false) { // get the content of the file $csv = self::arrayToString($array, $columns, $excludeColumns, $delimiter, $enclosure); @@ -68,7 +68,7 @@ public static function arrayToFile($path, array $array, array $columns = null, a * @param string[optional] $enclosure The enclosure character of the CSV. * @param string[optional] $lineEnding The line-ending of the CSV. */ - public static function arrayToString(array $array, array $columns = null, array $excludeColumns = null, $delimiter = ',', $enclosure = '"', $lineEnding = null) + public static function arrayToString(array $array, ?array $columns = null, ?array $excludeColumns = null, $delimiter = ',', $enclosure = '"', $lineEnding = null) { // validate array if(!empty($array) && !isset($array[0])) throw new SpoonFileException('Invalid array format.'); @@ -140,7 +140,7 @@ private static function download($path) $filename = end($explodedFilename); // set headers for download - $headers = array(); + $headers = []; $headers[] = 'Content-type: text/csv; charset=utf-8'; $headers[] = 'Content-Disposition: attachment; filename="' . $filename . '"'; @@ -171,7 +171,7 @@ private static function download($path) public static function escapeEnclosure($row, $enclosure) { // init var - $escaped = array(); + $escaped = []; // apply enclosure foreach($row as $key => $value) @@ -193,7 +193,7 @@ public static function escapeEnclosure($row, $enclosure) * @param string[optional] $delimiter The field delimiter of the CSV. * @param string[optional] $enclosure The enclosure character of the CSV. */ - public static function fileToArray($path, array $columns = array(), array $excludeColumns = null, $delimiter = ',', $enclosure = '"') + public static function fileToArray($path, array $columns = [], ?array $excludeColumns = null, $delimiter = ',', $enclosure = '"') { // reset variables $path = (string) $path; @@ -210,13 +210,13 @@ public static function fileToArray($path, array $columns = array(), array $exclu @ini_set('auto_detect_line_endings', 1); // init var - $rows = array(); + $rows = []; // open file $handle = @fopen($path, 'r'); // loop lines and store the rows - while(($row = @fgetcsv($handle, 0, (($delimiter == '') ? ',' : $delimiter), (($enclosure == '') ? '"' : $enclosure))) !== false) $rows[] = $row; + while(($row = @fgetcsv($handle, 0, (($delimiter == '') ? ',' : $delimiter), (($enclosure == '') ? '"' : $enclosure), escape: '\\')) !== false) $rows[] = $row; // close file @fclose($handle); @@ -231,7 +231,7 @@ public static function fileToArray($path, array $columns = array(), array $exclu array_shift($rows); // loop the rows - foreach($rows as $rowId => &$row) + foreach($rows as &$row) { // the keys of this row $keys = array_keys($row); @@ -354,7 +354,7 @@ private static function getDelimiterAndEnclosure($string, $delimiter = null, $en } // return the results - return array($delimiter, $enclosure); + return [$delimiter, $enclosure]; } @@ -368,11 +368,11 @@ private static function getDelimiterAndEnclosure($string, $delimiter = null, $en * @param string[optional] $delimiter The field delimiter of the CSV. * @param string[optional] $enclosure The enclosure character of the CSV. */ - public static function stringToArray($string, array $columns = array(), array $excludeColumns = null, $delimiter = ',', $enclosure = '"') + public static function stringToArray($string, array $columns = [], ?array $excludeColumns = null, $delimiter = ',', $enclosure = '"') { // reset variables $string = (string) $string; - $filename = dirname(__FILE__) . '/' . uniqid(); + $filename = __DIR__ . '/' . uniqid(); // save a tempfile SpoonFile::setContent($filename, $string); diff --git a/spoon/file/file.php b/spoon/file/file.php index 2e3d410..2b529a7 100644 --- a/spoon/file/file.php +++ b/spoon/file/file.php @@ -73,6 +73,7 @@ public static function download($sourceURL, $destinationPath, $overwrite = true) if($fileHandle === false) return false; $options[CURLOPT_URL] = $sourceURL; + $options[CURLOPT_FOLLOWLOCATION] = true; $options[CURLOPT_FILE] = $fileHandle; $options[CURLOPT_HEADER] = false; if(ini_get('open_basedir') == '' && ini_get('safe_mode' == 'Off')) $options[CURLOPT_FOLLOWLOCATION] = true; @@ -92,7 +93,6 @@ public static function download($sourceURL, $destinationPath, $overwrite = true) $httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE); // close - curl_close($curl); fclose($fileHandle); // validate the errornumber @@ -177,7 +177,7 @@ public static function getInfo($filename) $filename = (string) $filename; // init var - $units = array('B', 'KB', 'MB', 'GB', 'TB', 'PB'); + $units = ['B', 'KB', 'MB', 'GB', 'TB', 'PB']; // fetch pathinfo $pathInfo = pathinfo($filename); @@ -186,7 +186,7 @@ public static function getInfo($filename) @clearstatcache(); // build details array - $file = array(); + $file = []; $file['basename'] = $pathInfo['basename']; $file['extension'] = self::getExtension($filename); $file['name'] = substr($file['basename'], 0, strlen($file['basename']) - strlen($file['extension']) -1); @@ -235,7 +235,7 @@ public static function getList($path, $includeRegexp = null) } // define list - $files = array(); + $files = []; // directory exists if(SpoonDirectory::exists($path)) @@ -253,7 +253,7 @@ public static function getList($path, $includeRegexp = null) if($includeRegexp !== null) { // init var - $matches = array(); + $matches = []; // is this a match? if(preg_match($includeRegexp, $file, $matches) != 0) $files[] = $file; diff --git a/spoon/filter/filter.php b/spoon/filter/filter.php index 93e0539..d714930 100644 --- a/spoon/filter/filter.php +++ b/spoon/filter/filter.php @@ -34,7 +34,7 @@ class SpoonFilter * * @var array */ - private static $tlds = array( + private static $tlds = [ 'ac', 'ad', 'ae', 'aero', 'af', 'ag', 'ai', 'al', 'am', 'an', 'ao', 'aq', 'ar', 'arpa', 'as', 'asia', 'at', 'au', 'aw', 'ax', 'az', 'ba', 'bb', 'bd' ,'be', 'bf', 'bg', 'bh', 'bi', 'biz', 'bj', 'bm', 'bn', 'bo', 'br', 'bs', 'bt', 'bv', 'bw', 'by' ,'bz', 'ca', 'cat', 'cc' ,'cd', 'cf', 'cg', 'ch', 'ci', 'ck', 'cl', 'cm', 'cn', 'co', 'com', 'coop', 'cr', 'cu', 'cv', 'cx', 'cy', 'cz', @@ -60,7 +60,7 @@ class SpoonFilter 'wf', 'ws', 'ye', 'yt', 'yu', 'za', 'zm', 'zw' - ); + ]; /** @@ -74,7 +74,7 @@ class SpoonFilter public static function arrayMapRecursive($callback, array $array, $allowedKeys = null) { // has no elements - if(empty($array)) return array(); + if(empty($array)) return []; // check if there is a key restriction if(!empty($allowedKeys)) @@ -84,7 +84,7 @@ public static function arrayMapRecursive($callback, array $array, $allowedKeys = } // declare our result array - $results = array(); + $results = []; // loop the array foreach($array as $key => $value) @@ -106,7 +106,7 @@ public static function arrayMapRecursive($callback, array $array, $allowedKeys = } // more than 1 function given, so apply them all - if(is_array($callback)) $results[$key] = call_user_func_array($callback, array($value)); + if(is_array($callback)) $results[$key] = call_user_func_array($callback, [$value]); // just 1 function given else $results[$key] = $callback($value); @@ -156,16 +156,16 @@ public static function disableMagicQuotes() */ function fixMagicQuotes($value) { - $value = is_array($value) ? array_map('fixMagicQuotes', $value) : stripslashes($value); + $value = is_array($value) ? array_map(fixMagicQuotes(...), $value) : stripslashes((string) $value); return $value; } } // fix the thing with magic dust! - $_POST = array_map('fixMagicQuotes', $_POST); - $_GET = array_map('fixMagicQuotes', $_GET); - $_COOKIE = array_map('fixMagicQuotes', $_COOKIE); - $_REQUEST = array_map('fixMagicQuotes', $_REQUEST); + $_POST = array_map(fixMagicQuotes(...), $_POST); + $_GET = array_map(fixMagicQuotes(...), $_GET); + $_COOKIE = array_map(fixMagicQuotes(...), $_COOKIE); + $_REQUEST = array_map(fixMagicQuotes(...), $_REQUEST); } } @@ -178,7 +178,7 @@ function fixMagicQuotes($value) * @param mixed $defaultValue The default-value. * @param string[optional] $returnType The type that should be returned. */ - public static function getValue($variable, array $values = null, $defaultValue, $returnType = 'string') + public static function getValue($variable, ?array $values = null, $defaultValue = null, $returnType = 'string') { // redefine arguments $variable = !is_array($variable) ? (string) $variable : $variable; @@ -217,34 +217,14 @@ public static function getValue($variable, array $values = null, $defaultValue, * We have to define the return type. Too bad we cant force it within * a certain list of types, since that's what this method actually does. */ - switch($returnType) - { - // array - case 'array': - $value = ($value == '') ? array() : (array) $value; - break; - - // bool - case 'bool': - $value = (bool) $value; - break; - - // double/float - case 'double': - case 'float': - $value = (float) $value; - break; - - // int - case 'int': - $value = (int) $value; - break; - - // string - case 'string': - $value = (string) $value; - break; - } + $value = match ($returnType) { + 'array' => ($value == '') ? [] : (array) $value, + 'bool' => (bool) $value, + 'double', 'float' => (float) $value, + 'int' => (int) $value, + 'string' => (string) $value, + default => $value, + }; return $value; } @@ -262,7 +242,7 @@ public static function htmlentities($value, $charset = null, $quoteStyle = ENT_N { // init vars $charset = ($charset !== null) ? self::getValue($charset, Spoon::getCharsets(), Spoon::getCharset()) : Spoon::getCharset(); - $quoteStyle = self::getValue($quoteStyle, array(ENT_COMPAT, ENT_QUOTES, ENT_NOQUOTES), ENT_NOQUOTES); + $quoteStyle = self::getValue($quoteStyle, [ENT_COMPAT, ENT_QUOTES, ENT_NOQUOTES], ENT_NOQUOTES); // apply htmlentities $return = htmlentities((string) $value, $quoteStyle, $charset); @@ -273,7 +253,7 @@ public static function htmlentities($value, $charset = null, $quoteStyle = ENT_N * we're using a decent database layer, we don't need this shit and we're replacing * the double backslashes by its' html entity equivalent. */ - return str_replace(array('\\'), array('\'), $return); + return str_replace(['\\'], ['\'], $return); } @@ -289,7 +269,7 @@ public static function htmlentitiesDecode($value, $charset = null, $quoteStyle = { // init vars $charset = ($charset !== null) ? self::getValue($charset, Spoon::getCharsets(), Spoon::getCharset()) : Spoon::getCharset(); - $quoteStyle = self::getValue($quoteStyle, array(ENT_COMPAT, ENT_QUOTES, ENT_NOQUOTES), ENT_NOQUOTES); + $quoteStyle = self::getValue($quoteStyle, [ENT_COMPAT, ENT_QUOTES, ENT_NOQUOTES], ENT_NOQUOTES); // apply method return html_entity_decode((string) $value, $quoteStyle, $charset); @@ -475,7 +455,7 @@ public static function isFloat($value, $allowCommas = false) if(mb_strpos((string) $value, '.') !== false) { $value = rtrim($value, '0'); - if(substr($value, -1) == '.') $value = substr($value, 0, -1); + if(str_ends_with($value, '.')) $value = substr($value, 0, -1); } // validate @@ -515,20 +495,20 @@ public static function isInteger($value) * @return bool True if the request is coming from this site, false if not. * @param array[optional] $domains An array containing all known domains. */ - public static function isInternalReferrer(array $domains = null) + public static function isInternalReferrer(?array $domains = null) { // no referrer or host found if(!isset($_SERVER['HTTP_REFERER'])) return true; if(!isset($_SERVER['HTTP_HOST'])) return true; // get own & referrer host names - $referrer = parse_url($_SERVER['HTTP_REFERER']); + $referrer = parse_url((string) $_SERVER['HTTP_REFERER']); $referrer = $referrer['host']; $hostname = $_SERVER['HTTP_HOST']; // redefine hostname & domains - if(strpos($referrer, 'www.') === 0) $referrer = substr($referrer, 4); - if(strpos($hostname, 'www.') === 0) $hostname = substr($hostname, 4); + if(str_starts_with($referrer, 'www.')) $referrer = substr($referrer, 4); + if(str_starts_with((string) $hostname, 'www.')) $hostname = substr((string) $hostname, 4); $domains = ($domains === null) ? (array) $hostname : (array) $domains; // internal? @@ -678,7 +658,7 @@ public static function isPrice($value, $precision = 2, $allowNegative = false, $ if(mb_strpos($value, '.') !== false) { $value = rtrim($value, '0'); - if(substr($value, -1) == '.') $value = substr($value, 0, -1); + if(str_ends_with($value, '.')) $value = substr($value, 0, -1); } // no negatives allowed @@ -714,7 +694,7 @@ public static function isString($value) { $value = 'Array'; } - return (bool) preg_match('/^[^\x-\x1F]+$/', (string) $value); + return (bool) preg_match('/^[^\x00-\x1F]+$/', (string) $value); } @@ -806,7 +786,7 @@ public static function replaceURLsWithAnchors($value, $noFollow = true) $pattern = '/(((http|ftp|https):\/{2})?(([0-9a-z_-]+\.)+(' . implode('|', self::$tlds) . ')(:[0-9]+)?((\/([~0-9a-zA-Z\#\+\%@\.\/_-]+))?(\?[0-9a-zA-Z\+\%@\/&\[\];=_-]+)?)?))\b/imu'; // get matches - $value = preg_replace_callback($pattern, array('SpoonFilter', 'replaceURLsCallback'), $value); + $value = preg_replace_callback($pattern, ['SpoonFilter', 'replaceURLsCallback'], $value); // add noFollow-attribute if($noFollow) $value = str_replace('(.*\n*)\|isU', '', $string); - $string = preg_replace('|\(.*\n*)\|isU', '', $string); + $string = preg_replace('|\(.*\n*)\|isU', '', (string) $string); + $string = preg_replace('|\(.*\n*)\|isU', '', (string) $string); // replace images with their alternative content // eg. My image => My image - if($replaceImagesWithAltText) $string = preg_replace('|\]*alt="(.*)".*/\>|isU', '$1', $string); + if($replaceImagesWithAltText) $string = preg_replace('|\]*alt="(.*)".*/\>|isU', '$1', (string) $string); // replace links with the inner html of the link with the url between () // eg.: My site => My site (http://site.domain.com) - if($replaceAnchorsWithURL) $string = preg_replace('|(.*)|isU', '$2 ($1)', $string); + if($replaceAnchorsWithURL) $string = preg_replace('|(.*)|isU', '$2 ($1)', (string) $string); // check if we need to preserve paragraphs and/or breaks $exceptions = ($preserveParagraphLinebreaks) ? $exceptions . '

' : $exceptions; // strip HTML tags and preserve paragraphs - $string = strip_tags($string, $exceptions); + $string = strip_tags((string) $string, $exceptions); // remove multiple with a single one $string = preg_replace('/\n\s/', PHP_EOL, $string); - $string = preg_replace('/\n{2,}/', PHP_EOL, $string); + $string = preg_replace('/\n{2,}/', PHP_EOL, (string) $string); // for each linebreak, table row or- paragraph end we want an additional linebreak at the end if($preserveParagraphLinebreaks) { - $string = preg_replace('|

|', '', $string); - $string = preg_replace('|

|', PHP_EOL, $string); + $string = preg_replace('|

|', '', (string) $string); + $string = preg_replace('|

|', PHP_EOL, (string) $string); } // trim whitespace and strip HTML tags - $string = trim($string); + $string = trim((string) $string); // replace html entities that aren't replaced by SpoonFilter::htmlentitiesDecode (should be solved when using a newer Spoon Library) $string = str_replace('€', 'EUR', $string); @@ -960,11 +940,11 @@ public static function urlise($value, $charset = null) $charset = ($charset !== null) ? self::getValue($charset, Spoon::getCharsets(), Spoon::getCharset()) : Spoon::getCharset(); // reserved characters (RFC 3986) - $reservedCharacters = array( + $reservedCharacters = [ '/', '?', ':', '@', '#', '[', ']', '!', '$', '&', '\'', '(', ')', '*', '+', ',', ';', '=' - ); + ]; // remove reserved characters $value = str_replace($reservedCharacters, ' ', $value); @@ -989,7 +969,7 @@ public static function urlise($value, $charset = null) $value = preg_replace('/\-+/', '-', $value); // trim - signs - return trim($value, '-'); + return trim((string) $value, '-'); } } diff --git a/spoon/form/attributes.php b/spoon/form/attributes.php index 80d9866..386ec27 100644 --- a/spoon/form/attributes.php +++ b/spoon/form/attributes.php @@ -36,7 +36,7 @@ class SpoonFormAttributes extends SpoonFormElement */ public function getAttribute($name) { - return (isset($this->attributes[(string) $name])) ? $this->attributes[(string) $name] : null; + return $this->attributes[(string) $name] ?? null; } @@ -66,7 +66,7 @@ protected function getAttributesHTML(array $variables) foreach($this->attributes as $key => $value) { // class? - if($key == 'class' && is_callable(array($this, 'getClassHTML'))) + if($key == 'class' && is_callable([$this, 'getClassHTML'])) { $html .= $this->getClassHTML(); } diff --git a/spoon/form/button.php b/spoon/form/button.php index eff00ba..fec326d 100644 --- a/spoon/form/button.php +++ b/spoon/form/button.php @@ -103,13 +103,14 @@ public function getValue() * @return string * @param SpoonTemplate[optional] $template The template to parse the element in. */ + #[\Override] public function parse($template = null) { // start element $output = 'getAttributesHTML(array('[id]' => $this->attributes['id'], '[name]' => $this->attributes['name'], '[value]' => $this->getValue())) . ' />'; + $output .= $this->getAttributesHTML(['[id]' => $this->attributes['id'], '[name]' => $this->attributes['name'], '[value]' => $this->getValue()]) . ' />'; // parse if($template !== null) $template->assign('btn' . SpoonFilter::toCamelCase($this->attributes['name']), $output); @@ -126,7 +127,7 @@ public function parse($template = null) */ public function setType($type = 'submit') { - $this->type = SpoonFilter::getValue($type, array('button', 'reset', 'submit'), 'submit'); + $this->type = SpoonFilter::getValue($type, ['button', 'reset', 'submit'], 'submit'); return $this; } } diff --git a/spoon/form/checkbox.php b/spoon/form/checkbox.php index a46d410..83705bc 100644 --- a/spoon/form/checkbox.php +++ b/spoon/form/checkbox.php @@ -92,6 +92,7 @@ public function addError($error) * @return string * @param array $variables The variables to get the attribute-HTML for. */ + #[\Override] protected function getAttributesHTML(array $variables) { // init var @@ -256,6 +257,7 @@ public function isFilled($error = null) * @return string * @param SpoonTemplate[optional] $template The template to parse the element in. */ + #[\Override] public function parse($template = null) { // name required @@ -265,7 +267,7 @@ public function parse($template = null) $output = 'getAttributesHTML(array('[id]' => $this->attributes['id'], '[name]' => $this->attributes['name'])) . ' />'; + $output .= $this->getAttributesHTML(['[id]' => $this->attributes['id'], '[name]' => $this->attributes['name']]) . ' />'; // template if($template !== null) diff --git a/spoon/form/date.php b/spoon/form/date.php index f30806d..3899e2f 100644 --- a/spoon/form/date.php +++ b/spoon/form/date.php @@ -65,7 +65,7 @@ public function __construct($name, $value = null, $mask = null, $class = 'inputD * before the value is set, or the old mask (in case it differs) * will automatically be used. */ - $this->setMask(($mask !== null) ? $mask : $this->mask); + $this->setMask($mask ?? $this->mask); /** * The value will be filled based on the default input mask @@ -88,6 +88,7 @@ public function __construct($name, $value = null, $mask = null, $class = 'inputD * * @return string */ + #[\Override] public function getDefaultValue() { return $this->value; @@ -128,24 +129,24 @@ public function getTimestamp($year = null, $month = null, $day = null, $hour = n if($this->isValid()) { // define long mask - $longMask = str_replace(array('d', 'm', 'Y'), array('dd', 'mm', 'yy'), $this->mask); + $longMask = str_replace(['d', 'm', 'Y'], ['dd', 'mm', 'yy'], $this->mask); // year found - if(strpos($longMask, 'yy') !== false && $year === null) + if(str_contains($longMask, 'yy') && $year === null) { // redefine year $year = substr($data[$this->attributes['name']], strpos($longMask, 'yy'), 4); } // month found - if(strpos($longMask, 'mm') !== false && $month === null) + if(str_contains($longMask, 'mm') && $month === null) { // redefine month $month = substr($data[$this->attributes['name']], strpos($longMask, 'mm'), 2); } // day found - if(strpos($longMask, 'dd') !== false && $day === null) + if(str_contains($longMask, 'dd') && $day === null) { // redefine day $day = substr($data[$this->attributes['name']], strpos($longMask, 'dd'), 2); @@ -181,7 +182,7 @@ public function getValue() { // post/get data $data = $this->getMethod(true); - $value = isset($data[$this->getName()]) ? $data[$this->getName()] : ''; + $value = $data[$this->getName()] ?? ''; // submitted by post (may be empty) if(is_scalar($value)) @@ -212,7 +213,7 @@ public function isFilled($error = null) { // post/get data $data = $this->getMethod(true); - $value = isset($data[$this->getName()]) ? $data[$this->getName()] : ''; + $value = $data[$this->getName()] ?? ''; $value = is_array($value) ? 'Array' : trim((string) $value); // check filled status @@ -250,7 +251,7 @@ public function isValid($error = null) if(strlen((string) $data[$this->attributes['name']]) == $this->attributes['maxlength']) { // define long mask - $longMask = str_replace(array('d', 'm', 'y', 'Y'), array('dd', 'mm', 'y', 'yy'), $this->mask); + $longMask = str_replace(['d', 'm', 'y', 'Y'], ['dd', 'mm', 'y', 'yy'], $this->mask); // init vars $year = (int) date('Y'); @@ -258,7 +259,7 @@ public function isValid($error = null) $day = (int) date('d'); // validate year (yyyy) - if(strpos($longMask, 'yy') !== false) + if(str_contains($longMask, 'yy')) { // redefine year $year = substr($data[$this->attributes['name']], strpos($longMask, 'yy'), 4); @@ -279,7 +280,7 @@ public function isValid($error = null) } // validate year (yy) - if(strpos($longMask, 'y') !== false && strpos($longMask, 'yy') === false) + if(str_contains($longMask, 'y') && !str_contains($longMask, 'yy')) { // redefine year $year = substr($data[$this->attributes['name']], strpos($longMask, 'y'), 2); @@ -300,7 +301,7 @@ public function isValid($error = null) } // validate month (mm) - if(strpos($longMask, 'mm') !== false) + if(str_contains($longMask, 'mm')) { // redefine month $month = substr($data[$this->attributes['name']], strpos($longMask, 'mm'), 2); @@ -321,7 +322,7 @@ public function isValid($error = null) } // validate day (dd) - if(strpos($longMask, 'dd') !== false) + if(str_contains($longMask, 'dd')) { // redefine day $day = substr($data[$this->attributes['name']], strpos($longMask, 'dd'), 2); @@ -371,6 +372,7 @@ public function isValid($error = null) * @return string * @param SpoonTemplate[optional] $template The template to parse the element in. */ + #[\Override] public function parse($template = null) { // name is required @@ -380,7 +382,7 @@ public function parse($template = null) $output = 'getAttributesHTML(array('[id]' => $this->attributes['id'], '[name]' => $this->attributes['name'], '[value]' => $this->getValue())) . ' />'; + $output .= $this->getAttributesHTML(['[id]' => $this->attributes['id'], '[name]' => $this->attributes['name'], '[value]' => $this->getValue()]) . ' />'; // template if($template !== null) @@ -405,7 +407,7 @@ public function setMask($mask = null) $mask = ($mask !== null) ? (string) $mask : $this->mask; // allowed characters - $aCharachters = array( + $aCharachters = [ '.', ' ', '-', @@ -422,7 +424,7 @@ public function setMask($mask = null) 'n', 'Y', 'y', - ); + ]; // new mask $maskCorrected = ''; @@ -434,7 +436,7 @@ public function setMask($mask = null) if(in_array(substr($mask, $i, 1), $aCharachters)) $maskCorrected .= substr($mask, $i, 1); } - $formatMap = array( + $formatMap = [ 'd' => 'dd', 'D' => 'D', 'j' => 'd', @@ -446,7 +448,7 @@ public function setMask($mask = null) 'n' => 'm', 'Y' => 'yy', 'y' => 'y', - ); + ]; // new mask $this->mask = $maskCorrected; diff --git a/spoon/form/dropdown.php b/spoon/form/dropdown.php index f9612f4..2ce8a58 100644 --- a/spoon/form/dropdown.php +++ b/spoon/form/dropdown.php @@ -50,7 +50,7 @@ class SpoonFormDropdown extends SpoonFormAttributes * * @var array */ - private $defaultElement = array(); + private $defaultElement = []; /** @@ -66,15 +66,15 @@ class SpoonFormDropdown extends SpoonFormAttributes * * @var array */ - private $optionAttributes = array(); + private $optionAttributes = []; /** * Contains optgroups * - * @var bool + * @var array */ - private $optionGroups = false; + private $optionGroups = []; /** @@ -98,7 +98,7 @@ class SpoonFormDropdown extends SpoonFormAttributes * * @var array */ - protected $values = array(); + protected $values = []; /** @@ -111,7 +111,7 @@ class SpoonFormDropdown extends SpoonFormAttributes * @param string[optional] $class The CSS-class to be used. * @param string[optional] $classError The CSS-class to be used when there is an error. */ - public function __construct($name, array $values = null, $selected = null, $multipleSelection = false, $class = 'inputDropdown', $classError = 'inputDropdownError') + public function __construct($name, ?array $values = null, $selected = null, $multipleSelection = false, $class = 'inputDropdown', $classError = 'inputDropdownError') { // obligates fields $this->attributes['id'] = SpoonFilter::toCamelCase($name, '_', true); @@ -147,6 +147,7 @@ public function addError($error) * @return string * @param array $variables The variables to get the attributes-HTML for. */ + #[\Override] protected function getAttributesHTML(array $variables) { // init var @@ -248,7 +249,7 @@ public function getErrors() */ public function getOptionAttributes($value) { - return (isset($this->optionAttributes[(string) $value])) ? $this->optionAttributes[(string) $value] : array(); + return $this->optionAttributes[(string) $value] ?? []; } @@ -277,13 +278,13 @@ public function getSelected() $name = $this->attributes['name']; // reset selected - $this->selected = array(); + $this->selected = []; // field has been submitted if(isset($data[$name]) && is_array($data[$name]) && count($data[$name]) != 0) { // loop elements and add the value to the array - foreach($data[$name] as $label => $value) $this->selected[] = $value; + foreach($data[$name] as $value) $this->selected[] = $value; } } @@ -306,7 +307,7 @@ public function getValue() $data = $this->getMethod(true); // loop initial values and fill the array of allowed values - $allowedValues = array(); + $allowedValues = []; foreach($this->values as $key => $value) { // the current key represents an optgroup @@ -326,7 +327,7 @@ public function getValue() if(!$this->single) { // reset - $values = array(); + $values = []; // loop choices foreach((array) $data[$this->attributes['name']] as $value) @@ -347,7 +348,7 @@ public function getValue() { // rest $values = null; - $value = isset($data[$this->getName()]) ? $data[$this->getName()] : ''; + $value = $data[$this->getName()] ?? ''; $value = is_scalar($value) ? (string) $value : 'Array'; $value = htmlspecialchars($value, ENT_QUOTES); @@ -452,6 +453,7 @@ public function isFilled($error = null) * @return string * @param SpoonTemplate[optional] $template The template to parse the element in. */ + #[\Override] public function parse($template = null) { // name is required @@ -469,7 +471,7 @@ public function parse($template = null) } // add attributes - $output .= $this->getAttributesHTML(array('[id]' => $this->attributes['id'], '[name]' => $name)); + $output .= $this->getAttributesHTML(['[id]' => $this->attributes['id'], '[name]' => $name]); // end select tag $output .= ">\r\n"; @@ -621,7 +623,7 @@ public function setAllowExternalData($on = true) */ public function setDefaultElement($label, $value = null) { - $this->defaultElement = array((string) $label, (string) $value); + $this->defaultElement = [(string) $label, (string) $value]; if($value !== null) $this->values[$value] = (string) $label; return $this; } @@ -708,8 +710,10 @@ public function setSingle($single = true) * * @param array[optional] $values The possible values. Each value should have a label and value-key. */ - private function setValues(array $values = null) + private function setValues(?array $values = null) { + $values ??= []; + // has no items if(count($values) == 0) $this->setDefaultElement(''); diff --git a/spoon/form/element.php b/spoon/form/element.php index 3efc521..c8e6180 100644 --- a/spoon/form/element.php +++ b/spoon/form/element.php @@ -32,7 +32,7 @@ class SpoonFormElement * * @var array */ - protected $attributes = array(); + protected $attributes = []; /** @@ -56,7 +56,7 @@ class SpoonFormElement * * @var array */ - protected $reservedAttributes = array('type', 'name', 'value'); + protected $reservedAttributes = ['type', 'name', 'value']; /** @@ -152,7 +152,7 @@ public function setFormName($name) */ public function setMethod($method = 'post') { - $this->method = SpoonFilter::getValue($method, array('get', 'post'), 'post'); + $this->method = SpoonFilter::getValue($method, ['get', 'post'], 'post'); return $this; } } diff --git a/spoon/form/file.php b/spoon/form/file.php index 84dafd3..ae56361 100644 --- a/spoon/form/file.php +++ b/spoon/form/file.php @@ -146,7 +146,7 @@ public function getExtension($lowercase = true) */ public function getFileName($includeExtension = true) { - if($this->isFilled()) return (!$includeExtension) ? substr($_FILES[$this->attributes['name']]['name'], 0, strripos($_FILES[$this->attributes['name']]['name'], '.' . SpoonFile::getExtension($_FILES[$this->attributes['name']]['name'], false))) : $_FILES[$this->attributes['name']]['name']; + if($this->isFilled()) return (!$includeExtension) ? substr((string) $_FILES[$this->attributes['name']]['name'], 0, strripos((string) $_FILES[$this->attributes['name']]['name'], '.' . SpoonFile::getExtension($_FILES[$this->attributes['name']]['name'], false))) : $_FILES[$this->attributes['name']]['name']; return ''; } @@ -163,7 +163,7 @@ public function getFileSize($unit = 'kb', $precision = null) if($this->isFilled()) { // redefine unit - $unit = SpoonFilter::getValue(strtolower($unit), array('b', 'kb', 'mb', 'gb'), 'kb'); + $unit = SpoonFilter::getValue(strtolower((string) $unit), ['b', 'kb', 'mb', 'gb'], 'kb'); // fetch size $size = $_FILES[$this->attributes['name']]['size']; @@ -246,7 +246,6 @@ public function isAllowedMimeType(array $allowedTypes, $error = null) // file has been uploaded if($this->isFilled()) { - if (!is_file($_FILES[$this->attributes['name']]['tmp_name'])) return false; // get image properties @@ -312,7 +311,7 @@ public function isFilesize($size, $unit = 'kb', $operator = 'smaller', $error = $actualSize = $this->getFileSize($unit, 0); // operator - $operator = SpoonFilter::getValue(strtolower($operator), array('smaller', 'equal', 'greater'), 'smaller'); + $operator = SpoonFilter::getValue(strtolower((string) $operator), ['smaller', 'equal', 'greater'], 'smaller'); // smaller if($operator == 'smaller' && $actualSize < $size) return true; @@ -388,6 +387,7 @@ public function moveFile($path, $chmod = 0755) * @return string * @param SpoonTemplate[optional] $template The template to parse the element in. */ + #[\Override] public function parse($template = null) { // name is required @@ -397,7 +397,7 @@ public function parse($template = null) $output = 'getAttributesHTML(array('[id]' => $this->attributes['id'], '[name]' => $this->attributes['name'])) . ' />'; + $output .= $this->getAttributesHTML(['[id]' => $this->attributes['id'], '[name]' => $this->attributes['name']]) . ' />'; // parse to template if($template !== null) diff --git a/spoon/form/form.php b/spoon/form/form.php index e95dad8..9730cbd 100644 --- a/spoon/form/form.php +++ b/spoon/form/form.php @@ -57,7 +57,7 @@ class SpoonForm * * @var array */ - protected $fields = array(); + protected $fields = []; /** @@ -81,7 +81,7 @@ class SpoonForm * * @var array */ - protected $objects = array(); + protected $objects = []; /** @@ -89,7 +89,7 @@ class SpoonForm * * @var array */ - protected $parameters = array(); + protected $parameters = []; /** @@ -271,7 +271,7 @@ public function addDate($name, $value = null, $mask = null, $class = 'inputDate' * @param string[optional] $class The CSS-class to be used. * @param string[optional] $classError The CSS-class to be used when there is an error. */ - public function addDropdown($name, array $values = null, $selected = null, $multipleSelection = false, $class = 'inputDropdown', $classError = 'inputDropdownError') + public function addDropdown($name, ?array $values = null, $selected = null, $multipleSelection = false, $class = 'inputDropdown', $classError = 'inputDropdownError') { // add element $this->add(new SpoonFormDropdown($name, $values, $selected, $multipleSelection, $class, $classError)); @@ -886,7 +886,7 @@ public function getUseToken() public function getValues($excluded = null) { // redefine var - $excludedFields = array(); + $excludedFields = []; // has arguments if(func_num_args() != 0) @@ -900,12 +900,12 @@ public function getValues($excluded = null) } // values - $values = array(); + $values = []; // loop objects foreach($this->objects as $object) { - if(is_callable(array($object, 'getValue')) && !in_array($object->getName(), $excludedFields)) $values[$object->getName()] = $object->getValue(); + if(is_callable([$object, 'getValue']) && !in_array($object->getName(), $excludedFields)) $values[$object->getName()] = $object->getValue(); } // return data @@ -937,7 +937,7 @@ public function isCorrect($revalidate = false) public function isSubmitted() { // default array - $aForm = array(); + $aForm = []; // post if($this->method == 'post' && isset($_POST)) $aForm = $_POST; @@ -967,7 +967,7 @@ public function parse($template) foreach($this->objects as $name => $object) { // not excluded - if(!in_array($name, array('form', 'form_token'))) $object->parse($template); + if(!in_array($name, ['form', 'form_token'])) $object->parse($template); } // parse form tag @@ -982,9 +982,11 @@ public function parse($template) */ public function setAction($action) { + $action = (string) $action; + $action = str_replace('"', '&qout;', $action); - $this->action = (string) $action; + $this->action = $action; } @@ -1009,7 +1011,7 @@ protected function setCorrect($correct = true) */ public function setMethod($method = 'post') { - $this->method = SpoonFilter::getValue((string) $method, array('get', 'post'), 'post'); + $this->method = SpoonFilter::getValue((string) $method, ['get', 'post'], 'post'); return $this; } @@ -1170,8 +1172,8 @@ public function validate() foreach($this->objects as $oElement) { // check, since some objects don't have this method! - if(is_callable(array($oElement, 'getErrors')) - && trim($oElement->getErrors()) !== '' + if(is_callable([$oElement, 'getErrors']) + && trim((string) $oElement->getErrors()) !== '' ) { $errors[] = $oElement->getErrors(); }; diff --git a/spoon/form/hidden.php b/spoon/form/hidden.php index 838d5db..7a29c79 100644 --- a/spoon/form/hidden.php +++ b/spoon/form/hidden.php @@ -94,7 +94,7 @@ public function isFilled() { // post/get data $data = $this->getMethod(true); - $value = isset($data[$this->getName()]) ? $data[$this->getName()] : ''; + $value = $data[$this->getName()] ?? ''; $value = is_array($value) ? 'Array' : trim((string) $value); return $value != ''; } @@ -106,13 +106,14 @@ public function isFilled() * @return string * @param SpoonTemplate[optional] $template The template to parse the element in. */ - public function parse($template = null) + #[\Override] + public function parse($template = null) { // start html generation $output = 'attributes['id'])) $attributes['[id]'] = $this->attributes['id']; $attributes['[name]'] = $this->attributes['name']; $attributes['[value]'] = $this->getValue(); diff --git a/spoon/form/image.php b/spoon/form/image.php index e488498..6590e89 100644 --- a/spoon/form/image.php +++ b/spoon/form/image.php @@ -88,6 +88,7 @@ public function createThumbnail($filename, $width = null, $height = null, $allow * @return string * @param bool[optional] $lowercase Should the extensions be returned in lowercase? */ + #[\Override] public function getExtension($lowercase = true) { if($this->isSubmitted()) diff --git a/spoon/form/multi_checkbox.php b/spoon/form/multi_checkbox.php index b4d9bb5..f191c06 100644 --- a/spoon/form/multi_checkbox.php +++ b/spoon/form/multi_checkbox.php @@ -40,7 +40,7 @@ class SpoonFormMultiCheckbox extends SpoonFormElement * * @var array */ - private $checked = array(); + private $checked = []; /** @@ -91,7 +91,6 @@ public function __construct($name, array $values, $checked = null, $class = 'inp // custom optional fields if($checked !== null) $this->setChecked($checked); - $this->classError = (string) $class; } @@ -159,6 +158,7 @@ public function getErrors() * * @return string */ + #[\Override] public function getName() { return $this->name; @@ -184,7 +184,7 @@ public function getRawValues() public function getValue() { // default value - $values = array(); + $values = []; // submitted by post (may be empty) if($this->isSubmitted()) @@ -248,6 +248,7 @@ public function isFilled($error = null) * @return string * @param SpoonTemplate[optional] $template The template to parse the element in. */ + #[\Override] public function parse($template = null) { // name required @@ -258,14 +259,14 @@ public function parse($template = null) { // init vars $name = 'chk' . SpoonFilter::toCamelCase($this->name); - $element = array(); + $element = []; $element[$name] = 'getChecked())) $element[$name] .= ' checked="checked"'; // add attributes - $element[$name] .= $this->getAttributesHTML($value, array('[id]' => $this->variables[$value]['id'], '[value]' => $value)); + $element[$name] .= $this->getAttributesHTML($value, ['[id]' => $this->variables[$value]['id'], '[value]' => $value]); // add variables to this element foreach($this->variables[$value] as $variableKey => $variableValue) $element[$variableKey] = $variableValue; diff --git a/spoon/form/password.php b/spoon/form/password.php index 5663a0d..6d9c2ff 100644 --- a/spoon/form/password.php +++ b/spoon/form/password.php @@ -151,7 +151,7 @@ public function isFilled($error = null) { // post/get data $data = $this->getMethod(true); - $value = isset($data[$this->getName()]) ? $data[$this->getName()] : ''; + $value = $data[$this->getName()] ?? ''; if(is_array($value)) { $value = 'Array'; @@ -267,6 +267,7 @@ public function isValidAgainstRegexp($regexp, $error = null) * @return string * @param SpoonTemplate[optional] $template The template to parse the element in. */ + #[\Override] public function parse($template = null) { // name is required @@ -276,7 +277,7 @@ public function parse($template = null) $output = 'getAttributesHTML(array('[id]' => $this->attributes['id'], '[name]' => $this->attributes['name'], '[value]' => $this->getValue())) . ' />'; + $output .= $this->getAttributesHTML(['[id]' => $this->attributes['id'], '[name]' => $this->attributes['name'], '[value]' => $this->getValue()]) . ' />'; // template if($template !== null) diff --git a/spoon/form/radiobutton.php b/spoon/form/radiobutton.php index e990277..ec1fcc3 100644 --- a/spoon/form/radiobutton.php +++ b/spoon/form/radiobutton.php @@ -150,7 +150,7 @@ public function getChecked() // form submitted if($this->isSubmitted()) { - $value = isset($data[$this->getName()]) ? $data[$this->getName()] : ''; + $value = $data[$this->getName()] ?? ''; if(is_array($value)) { $value = 'Array'; @@ -183,6 +183,7 @@ public function getErrors() * * @return string */ + #[\Override] public function getName() { return $this->name; @@ -222,7 +223,7 @@ public function getValue() // external data NOT allowed else { - $submittedValue = isset($data[$this->name]) ? $data[$this->name] : ''; + $submittedValue = $data[$this->name] ?? ''; if(is_array($submittedValue)) { $submittedValue = 'Array'; @@ -249,7 +250,7 @@ public function isFilled($error = null) { // post/get data $data = $this->getMethod(true); - $value = isset($data[$this->getName()]) ? $data[$this->getName()] : ''; + $value = $data[$this->getName()] ?? ''; $value = is_array($value) ? 'Array' : trim((string) $value); // correct @@ -269,6 +270,7 @@ public function isFilled($error = null) * @param SpoonTemplate $template The template to parse the element in. * @throws SpoonFormException */ + #[\Override] public function parse($template = null) { // name required @@ -281,14 +283,14 @@ public function parse($template = null) { // init vars $name = 'rbt' . SpoonFilter::toCamelCase($this->name); - $element = array(); + $element = []; $element[$name] = 'getChecked()) $element[$name] .= ' checked="checked"'; // add attributes - $element[$name] .= $this->getAttributesHTML($value, array('[id]' => $this->variables[$value]['id'], '[value]' => $value)); + $element[$name] .= $this->getAttributesHTML($value, ['[id]' => $this->variables[$value]['id'], '[value]' => $value]); // add variables to this element foreach($this->variables[$value] as $variableKey => $variableValue) $element[$variableKey] = $variableValue; diff --git a/spoon/form/text.php b/spoon/form/text.php index 1dfcb60..8f4f269 100644 --- a/spoon/form/text.php +++ b/spoon/form/text.php @@ -40,7 +40,7 @@ class SpoonFormText extends SpoonFormInput * * @var array */ - protected $reservedAttributes = array('name', 'value'); + protected $reservedAttributes = ['name', 'value']; /** @@ -335,9 +335,7 @@ public function isFilled($error = null) { // post/get data $data = $this->getMethod(true); - $value = isset($data[$this->getName()]) - ? $data[$this->getName()] - : ''; + $value = $data[$this->getName()] ?? ''; $value = is_array($value) ? 'Array' : trim((string) $value); // validate @@ -782,6 +780,7 @@ public function isValidAgainstRegexp($regexp, $error = null) * @return string * @param SpoonTemplate[optional] $template The template to parse the element in. */ + #[\Override] public function parse($template = null) { // name is required @@ -792,7 +791,7 @@ public function parse($template = null) $output = 'getAttributesHTML(array('[id]' => $this->attributes['id'], '[name]' => $this->attributes['name'], '[value]' => $this->getValue())) . ' />'; + $output .= $this->getAttributesHTML(['[id]' => $this->attributes['id'], '[name]' => $this->attributes['name'], '[value]' => $this->getValue()]) . ' />'; // template if($template !== null) diff --git a/spoon/form/textarea.php b/spoon/form/textarea.php index c38c1c2..eb865a6 100644 --- a/spoon/form/textarea.php +++ b/spoon/form/textarea.php @@ -89,7 +89,7 @@ public function getValue($allowHTML = null) if(isset($data[$this->getName()])) { // value - $value = isset($data[$this->getName()]) ? $data[$this->getName()] : ''; + $value = $data[$this->getName()] ?? ''; if(is_array($value)) { $value = 'Array'; @@ -177,7 +177,7 @@ public function isFilled($error = null) { // post/get data $data = $this->getMethod(true); - $value = isset($data[$this->getName()]) ? $data[$this->getName()] : ''; + $value = $data[$this->getName()] ?? ''; if(is_array($value)) { $value = 'Array'; @@ -293,6 +293,7 @@ public function isString($error = null) * @return string * @param SpoonTemplate[optional] $template The template to parse the element in. */ + #[\Override] public function parse($template = null) { // name is required @@ -302,13 +303,13 @@ public function parse($template = null) $output = 'getAttributesHTML(array('[id]' => $this->attributes['id'], '[name]' => $this->attributes['name'], '[value]' => $this->getValue(false))); + $output .= $this->getAttributesHTML(['[id]' => $this->attributes['id'], '[name]' => $this->attributes['name'], '[value]' => $this->getValue(false)]); // close first tag $output .= '>'; // add value - $output .= str_replace(array('"', '<', '>'), array('"', '<', '>'), $this->getValue()); + $output .= str_replace(['"', '<', '>'], ['"', '<', '>'], $this->getValue()); // end tag $output .= ''; diff --git a/spoon/form/time.php b/spoon/form/time.php index 9e83f3e..5c68557 100644 --- a/spoon/form/time.php +++ b/spoon/form/time.php @@ -169,7 +169,7 @@ public function isValid($error = null) if(strlen($data) == 5) { // allowed characters - $aCharacters = array(':', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'); + $aCharacters = [':', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9']; // replace every character if it's not in the list! for($i = 0; $i < strlen($data); $i++) @@ -178,7 +178,7 @@ public function isValid($error = null) } // maxlength checks out (needs to be equal) - if(strlen($time) == 5 && strpos($time, ':') !== false) + if(strlen($time) == 5 && str_contains($time, ':')) { // define hour & minutes $hour = (int) substr($time, 0, 2); @@ -210,6 +210,7 @@ public function isValid($error = null) * @return string * @param SpoonTemplate[optional] $template The template to parse the element in. */ + #[\Override] public function parse($template = null) { // name is required @@ -219,7 +220,7 @@ public function parse($template = null) $output = 'getAttributesHTML(array('[id]' => $this->attributes['id'], '[name]' => $this->attributes['name'], '[value]' => $this->getValue())) . ' />'; + $output .= $this->getAttributesHTML(['[id]' => $this->attributes['id'], '[name]' => $this->attributes['name'], '[value]' => $this->getValue()]) . ' />'; // template if($template !== null) diff --git a/spoon/http/http.php b/spoon/http/http.php index 83dfda0..bd85db8 100644 --- a/spoon/http/http.php +++ b/spoon/http/http.php @@ -33,7 +33,7 @@ class SpoonHTTP * * @var array */ - protected static $codes = array( + protected static $codes = [ 200 => '200 OK', 301 => '301 Moved Permanently', 302 => '302 Found', @@ -46,7 +46,7 @@ class SpoonHTTP 410 => '410 Gone', 500 => '500 Internal Server Error', 501 => '501 Not Implemented', - ); + ]; /** * Get content from an URL. @@ -55,7 +55,7 @@ class SpoonHTTP * @param string $URL The URL of the webpage that should be retrieved. * @param array[optional] $cURLoptions Extra options to be passed on with the cURL-request. */ - public static function getContent($URL, array $cURLoptions = null) + public static function getContent($URL, ?array $cURLoptions = null) { // check if curl is available if(!function_exists('curl_init')) throw new SpoonFileException('This method requires cURL (http://php.net/curl), it seems like the extension isn\'t installed.'); @@ -87,11 +87,8 @@ public static function getContent($URL, array $cURLoptions = null) $errorNumber = curl_errno($curl); $errorMessage = curl_error($curl); - // close - curl_close($curl); - // validate - if($errorNumber != '') throw new SpoonHTTPException($errorMessage); + if($errorNumber != 0) throw new SpoonHTTPException($errorMessage); // return the content return (string) $response; @@ -116,7 +113,7 @@ public static function getHeadersList() */ public static function getIp() { - return (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR']; + return $_SERVER['HTTP_X_FORWARDED_FOR'] ?? $_SERVER['REMOTE_ADDR']; } diff --git a/spoon/locale/data/continent_countries.php b/spoon/locale/data/continent_countries.php index 149d1f5..7163868 100644 --- a/spoon/locale/data/continent_countries.php +++ b/spoon/locale/data/continent_countries.php @@ -1,25 +1,25 @@ 'january', 'february', 'march', 'april', 'may', 'june', 'july', 'august', 'september', 'october', 'november', 'december'); + $months = [1 => 'january', 'february', 'march', 'april', 'may', 'june', 'july', 'august', 'september', 'october', 'november', 'december']; $language = SpoonFilter::getValue($language, self::$languages, 'en'); - $locale = array(); + $locale = []; // which month? if(SpoonFilter::isInteger($month)) $month = SpoonFilter::getValue($month, range(1, 12), 1); @@ -354,7 +354,7 @@ public static function getMonths($language = 'en', $abbreviated = false) { // init vars $language = SpoonFilter::getValue($language, self::$languages, 'en'); - $locale = array(); + $locale = []; // fetch file require 'data/' . $language . '.php'; @@ -375,14 +375,14 @@ public static function getMonths($language = 'en', $abbreviated = false) public static function getWeekDay($day, $language = 'en', $abbreviated = false) { // init vars - $dayIndexes = array('sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat'); - $dayNames = array('sunday' => 'sun', 'monday' => 'mon', 'tuesday' => 'tue', 'wednesday' => 'wed', 'thursday' => 'thu', 'friday' => 'fri', 'saturday' => 'sat'); + $dayIndexes = ['sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat']; + $dayNames = ['sunday' => 'sun', 'monday' => 'mon', 'tuesday' => 'tue', 'wednesday' => 'wed', 'thursday' => 'thu', 'friday' => 'fri', 'saturday' => 'sat']; $language = SpoonFilter::getValue($language, self::$languages, 'en'); - $locale = array(); + $locale = []; // which day? - if(SpoonFilter::isInteger($day)) $day = $dayIndexes[SpoonFilter::getValue(strtolower($day), range(0, 6), 0)]; - else $day = $dayNames[SpoonFilter::getValue(strtolower($day), array_keys($dayNames), 'sunday')]; + if(SpoonFilter::isInteger($day)) $day = $dayIndexes[SpoonFilter::getValue(strtolower((string) $day), range(0, 6), 0)]; + else $day = $dayNames[SpoonFilter::getValue(strtolower((string) $day), array_keys($dayNames), 'sunday')]; // fetch file require 'data/' . $language . '.php'; @@ -404,8 +404,8 @@ public static function getWeekDays($language = 'en', $abbreviated = false, $firs { // init vars $language = SpoonFilter::getValue($language, self::$languages, 'en'); - $firstDay = SpoonFilter::getValue($firstDay, array('monday', 'sunday'), 'monday'); - $locale = array(); + $firstDay = SpoonFilter::getValue($firstDay, ['monday', 'sunday'], 'monday'); + $locale = []; // fetch file require 'data/' . $language . '.php'; diff --git a/spoon/spoon.php b/spoon/spoon.php index 73c3ecd..c5f775e 100644 --- a/spoon/spoon.php +++ b/spoon/spoon.php @@ -56,7 +56,7 @@ '; Spoon::setDebugMessage($output); -spl_autoload_register(array('Spoon', 'autoLoader')); +spl_autoload_register(['Spoon', 'autoLoader']); /** * This class holds objects/data in a name based registry to make them easily @@ -75,7 +75,7 @@ class Spoon * * @var array */ - private static $registry = array(); + private static $registry = []; /* @@ -101,7 +101,7 @@ public static function autoLoader($class) $class = strtolower($class); // list of classes and their location - $classes = array(); + $classes = []; $classes['spoondatabase'] = 'database/database.php'; $classes['spoondatagrid'] = 'datagrid/datagrid.php'; $classes['spoondatagridcolumn'] = 'datagrid/column.php'; @@ -172,7 +172,7 @@ public static function dump($var, $exit = true) if(!$hasXdebugVarDump) { $output = preg_replace('/\]\=\>\n(\s+)/m', '] => ', $output); - $output = '
' . htmlspecialchars($output, ENT_QUOTES, Spoon::getCharset()) . '
'; + $output = '
' . htmlspecialchars((string) $output, ENT_QUOTES, Spoon::getCharset()) . '
'; } echo $output; @@ -227,7 +227,7 @@ public static function getCharset() */ public static function getCharsets() { - return array('utf-8', 'iso-8859-1', 'iso-8859-15'); + return ['utf-8', 'iso-8859-1', 'iso-8859-15']; } diff --git a/spoon/template/compiler.php b/spoon/template/compiler.php index 7618a59..0a13b51 100644 --- a/spoon/template/compiler.php +++ b/spoon/template/compiler.php @@ -69,7 +69,7 @@ class SpoonTemplateCompiler * * @var array */ - protected $forms = array(); + protected $forms = []; /** @@ -77,7 +77,7 @@ class SpoonTemplateCompiler * * @var array */ - protected $iterations = array(); + protected $iterations = []; /** @@ -93,7 +93,7 @@ class SpoonTemplateCompiler * * @var array */ - protected $modifiers = array(); + protected $modifiers = []; /** @@ -117,7 +117,7 @@ class SpoonTemplateCompiler * * @var array */ - protected $templateVariables = array(); + protected $templateVariables = []; /** @@ -125,10 +125,14 @@ class SpoonTemplateCompiler * * @var array */ - protected $variables = array(); + protected $variables = []; private $debug; + /** + * @var array + */ + private array $files; /** * Class constructor. @@ -184,7 +188,7 @@ protected function parse() if(!$this->parsed) { // while developing, you might want to know about the undefined indexes - $errorReporting = ($this->debug) ? 'E_ALL | E_STRICT' : 0; + $errorReporting = ($this->debug) ? 'E_ALL' : 0; $displayErrors = ($this->debug) ? 'On' : 'Off'; // add to the list of parsed files @@ -296,7 +300,7 @@ protected function parseCycle($content, $iteration) if(preg_match_all($pattern, $content, $matches, PREG_SET_ORDER)) { // loop matches - foreach($matches as $i => $match) + foreach($matches as $match) { // cycles pattern $pattern = '/:("[^"]*?"|\'[^\']*?\'|[^:]*)/'; @@ -313,7 +317,7 @@ protected function parseCycle($content, $iteration) foreach($arguments[1] as &$argument) { // inside a string - if(in_array(substr($argument, 0, 1), array('\'', '"'))) + if(in_array(substr($argument, 0, 1), ['\'', '"'])) { // strip quotes $argument = substr($argument, 1, -1); @@ -359,11 +363,11 @@ protected function parseForms($content) foreach($matches[1] as $name) { // init vars - $search = array(); - $replace = array(); + $search = []; + $replace = []; // start & close tag - $search = array('{form:' . $name . '}', '{/form:' . $name . '}'); + $search = ['{form:' . $name . '}', '{/form:' . $name . '}']; // using UTF-8 as charset if(Spoon::getCharset() == 'utf-8') @@ -426,7 +430,7 @@ protected function parseIncludes($content) $search = $match[0]; // inside a string - if(in_array(substr($match[1], 0, 1), array('\'', '"'))) + if(in_array(substr($match[1], 0, 1), ['\'', '"'])) { // strip quotes $match[1] = substr($match[1], 1, -1); @@ -659,7 +663,7 @@ protected function parseOptions($content) $pattern = '/\{option:(\!?)([a-z0-9_]*)((\.[a-z0-9_]*)*)(-\>[a-z0-9_]*((\.[a-z0-9_]*)*))?}.*?\{\/option:\\1\\2\\3\\5?\}/is'; // init vars - $options = array(); + $options = []; $variable = ''; $objectVariable = ''; $baseVariable = ''; @@ -739,14 +743,14 @@ protected function parseOptions($content) } // init vars - $search = array(); - $replace = array(); + $search = []; + $replace = []; // not yet used $options[] = $match; // set option - $option = $match[2] . $match[3] . (isset($match[5]) ? $match[5] : ''); + $option = $match[2] . $match[3] . ($match[5] ?? ''); // search for $search[] = '{option:' . $option . '}'; @@ -956,7 +960,7 @@ protected function parseVariables($content) foreach($arguments[1] as $argument) { // string argument? - if(in_array(substr($argument, 0, 1), array('\'', '"'))) + if(in_array(substr($argument, 0, 1), ['\'', '"'])) { // in compiled code: single quotes! (and escape single quotes in the content!) $argument = '\'' . str_replace('\'', '\\\'', substr($argument, 1, -1)) . '\''; @@ -985,7 +989,7 @@ protected function parseVariables($content) * certainly already be parsed because we parse our variables outwards. */ // temporary variable which is a list of 'variables to check before parsing' - $variables = array($variable); + $variables = [$variable]; // loop all known template variables foreach($this->templateVariables as $key => $value) @@ -997,7 +1001,7 @@ protected function parseVariables($content) if($this->debug) { // check if this variable is found - if(strpos($match[0], '[$' . $key . ']') !== false) + if(str_contains($match[0], '[$' . $key . ']')) { // add variable name to list of 'variables to check before parsing' $variables = array_merge($variables, $value['variables']); @@ -1009,22 +1013,22 @@ protected function parseVariables($content) $this->templateVariables[$varKey]['content'] = $PHP; // holds checks to see if this variable can be parsed (along with the variables that may be used inside it) - $exists = array(); + $exists = []; // loop variables foreach((array) $variables as $variable) { // get array containing variable - if(preg_match('/->get([a-zA-Z_]*)\(\)$/i', $variable)) + if(preg_match('/->get([a-zA-Z_]*)\(\)$/i', (string) $variable)) { // we're working with objects - $object = preg_replace('/->(get[a-zA-Z_]*)\(\)$/i', '', $variable); + $object = preg_replace('/->(get[a-zA-Z_]*)\(\)$/i', '', (string) $variable); // get method name - preg_match('/->(get[a-zA-Z_]*)\(\)$/i', $variable, $variable); + preg_match('/->(get[a-zA-Z_]*)\(\)$/i', (string) $variable, $variable); $method = $variable[1]; - if(preg_match('/\[\'[a-z_][a-z0-9_]*\'\]/i', $object, $matches)) + if(preg_match('/\[\'[a-z_][a-z0-9_]*\'\]/i', (string) $object, $matches)) { $exists[] = 'is_object(' . $object . ')'; $exists[] = 'method_exists(' . $object . ', \'' . $method . '\')'; @@ -1034,18 +1038,18 @@ protected function parseVariables($content) } else { - $array = preg_replace('/(\[\'[a-z_][a-z0-9_]*\'\])$/i', '', $variable); + $array = preg_replace('/(\[\'[a-z_][a-z0-9_]*\'\])$/i', '', (string) $variable); // get variable name - preg_match('/\[\'([a-z_][a-z0-9_]*)\'\]$/i', $variable, $variable); + preg_match('/\[\'([a-z_][a-z0-9_]*)\'\]$/i', (string) $variable, $variable); $variable = $variable[1]; // container array is index of higher array - if(preg_match('/\[\'[a-z_][a-z0-9_]*\'\](?!->)/i', $array)) $exists[] = 'isset(' . $array . ')'; + if(preg_match('/\[\'[a-z_][a-z0-9_]*\'\](?!->)/i', (string) $array)) $exists[] = 'isset(' . $array . ')'; $exists[] = 'array_key_exists(\'' . $variable . '\', (array) ' . $array . ')'; // it could be an object in an iteration, add if statements for objects - $existsObject = array(); + $existsObject = []; $existsObject[] = 'is_object(' . $array . ')'; $existsObject[] = 'method_exists(' . $array . ', \'get' . SpoonFilter::toCamelCase($variable) . '\')'; $this->templateVariables[$varKey]['if_object'] = implode(' && ', $existsObject); @@ -1107,7 +1111,7 @@ protected function prepareIterations($content) while(1) { // replace iteration names to ensure that they're unique - $content = preg_replace_callback($pattern, array($this, 'prepareIterationsCallback'), $content, -1, $count); + $content = preg_replace_callback($pattern, $this->prepareIterationsCallback(...), (string) $content, -1, $count); // break the loop, no matches were found if(!$count) break; @@ -1259,7 +1263,7 @@ protected function stripComments($content) do { // strip comments from output - $content = preg_replace('/\{\*(?!.*?\{\*).*?\*\}/s', '', $content, -1, $count); + $content = preg_replace('/\{\*(?!.*?\{\*).*?\*\}/s', '', (string) $content, -1, $count); } while($count > 0); diff --git a/spoon/template/modifiers.php b/spoon/template/modifiers.php index a967c25..dab1a65 100644 --- a/spoon/template/modifiers.php +++ b/spoon/template/modifiers.php @@ -32,11 +32,11 @@ class SpoonTemplateModifiers * * @var array */ - private static $modifiers = array('addslashes' => 'addslashes', - 'createhtmllinks' => array('SpoonTemplateModifiers', 'createHTMLLinks'), - 'date' => array('SpoonTemplateModifiers', 'date'), - 'htmlentities' => array('SpoonFilter', 'htmlentities'), - 'lowercase' => array('SpoonTemplateModifiers', 'lowercase'), + private static $modifiers = ['addslashes' => 'addslashes', + 'createhtmllinks' => ['SpoonTemplateModifiers', 'createHTMLLinks'], + 'date' => ['SpoonTemplateModifiers', 'date'], + 'htmlentities' => ['SpoonFilter', 'htmlentities'], + 'lowercase' => ['SpoonTemplateModifiers', 'lowercase'], 'ltrim' => 'ltrim', 'nl2br' => 'nl2br', 'repeat' => 'str_repeat', @@ -46,9 +46,9 @@ class SpoonTemplateModifiers 'stripslashes' => 'stripslashes', 'substring' => 'substr', 'trim' => 'trim', - 'ucfirst' => array('SpoonFilter', 'ucfirst'), + 'ucfirst' => ['SpoonFilter', 'ucfirst'], 'ucwords' => 'ucwords', - 'uppercase' => array('SpoonTemplateModifiers', 'uppercase')); + 'uppercase' => ['SpoonTemplateModifiers', 'uppercase']]; /** @@ -56,7 +56,7 @@ class SpoonTemplateModifiers */ public static function clearModifiers() { - self::$modifiers = array(); + self::$modifiers = []; } @@ -133,7 +133,7 @@ public static function mapModifier($name, $function) if(count($function) != 2) throw new SpoonTemplateException('The array should contain the class and static method.'); // method doesn't exist - if(!is_callable(array($function[0], $function[1]))) throw new SpoonTemplateException('The method "' . $function[1] . '" in the class ' . $function[0] . ' does not exist.'); + if(!is_callable([$function[0], $function[1]])) throw new SpoonTemplateException('The method "' . $function[1] . '" in the class ' . $function[0] . ' does not exist.'); // all fine self::$modifiers[(string) $name] = $function; diff --git a/spoon/template/template.php b/spoon/template/template.php index f9c96ba..dd98357 100644 --- a/spoon/template/template.php +++ b/spoon/template/template.php @@ -37,7 +37,7 @@ class SpoonTemplate * * @var array */ - protected $cache = array(); + protected $cache = []; /** @@ -69,7 +69,7 @@ class SpoonTemplate * * @var array */ - protected $forms = array(); + protected $forms = []; /** @@ -77,7 +77,7 @@ class SpoonTemplate * * @var array */ - protected $iterations = array(); + protected $iterations = []; /** @@ -85,7 +85,7 @@ class SpoonTemplate * * @var array */ - protected $variables = array(); + protected $variables = []; /** @@ -344,8 +344,7 @@ public function display($template) */ public function getAssignedValue($variable) { - if(isset($this->variables[(string) $variable])) return $this->variables[(string) $variable]; - return null; + return $this->variables[(string) $variable] ?? null; } diff --git a/spoon/tests/SpoonTest.php b/spoon/tests/SpoonTest.php index 7495723..d29af63 100644 --- a/spoon/tests/SpoonTest.php +++ b/spoon/tests/SpoonTest.php @@ -2,7 +2,7 @@ use PHPUnit\Framework\TestCase; -$includePath = dirname(dirname(dirname(__FILE__))); +$includePath = dirname(__FILE__, 3); set_include_path(get_include_path() . PATH_SEPARATOR . $includePath); require_once 'spoon/spoon.php'; @@ -35,7 +35,7 @@ public function testExists() public function testSet() { // set value - $value = array('Davy Hellemans', 'Tijs Verkoyen', 'Dave Lens', 'Matthias Mullie'); + $value = ['Davy Hellemans', 'Tijs Verkoyen', 'Dave Lens', 'Matthias Mullie']; $this->assertEquals(Spoon::set('salad_fingers', $value), $value); // get rid of value diff --git a/spoon/tests/database/SpoonDatabaseLargeDataSet.php b/spoon/tests/database/SpoonDatabaseLargeDataSet.php index e852e3f..7f9d60f 100644 --- a/spoon/tests/database/SpoonDatabaseLargeDataSet.php +++ b/spoon/tests/database/SpoonDatabaseLargeDataSet.php @@ -17,7 +17,7 @@ * */ -$includePath = dirname(dirname(dirname(dirname(__FILE__)))); +$includePath = dirname(__FILE__, 4); set_include_path(get_include_path() . PATH_SEPARATOR . $includePath); require_once 'spoon/spoon.php'; @@ -77,7 +77,7 @@ public function testInsert() public function testGetNumRows() { $this->assertEquals(self::NUMBER_OF_ROWS, $this->db->getNumRows('SELECT id FROM users')); - $this->assertEquals(10000, $this->db->getNumRows('SELECT id FROM users LIMIT ?', array(10000))); + $this->assertEquals(10000, $this->db->getNumRows('SELECT id FROM users LIMIT ?', [10000])); } } diff --git a/spoon/tests/database/SpoonDatabaseTest.php b/spoon/tests/database/SpoonDatabaseTest.php index 2044390..7039859 100644 --- a/spoon/tests/database/SpoonDatabaseTest.php +++ b/spoon/tests/database/SpoonDatabaseTest.php @@ -2,7 +2,7 @@ use PHPUnit\Framework\TestCase; -$includePath = dirname(dirname(dirname(dirname(__FILE__)))); +$includePath = dirname(__FILE__, 4); set_include_path(get_include_path() . PATH_SEPARATOR . $includePath); require_once 'spoon/spoon.php'; @@ -25,7 +25,7 @@ public function testExecute() // create database try { $this->db->execute('CREATE DATABASE IF NOT EXISTS spoon_tests'); - } catch (SpoondatabaseException $e) { + } catch (SpoondatabaseException) { $this->fail('You should manually create a database "spoon_tests"'); } @@ -67,9 +67,9 @@ public function testExecute() // do nothing $this->db->execute('SELECT * FROM users LIMIT ?', 10); - $this->db->execute('SELECT * FROM users limit :limit', array(':limit' => 10)); + $this->db->execute('SELECT * FROM users limit :limit', [':limit' => 10]); $this->expectException(PDOException::class); - $this->db->execute('SELECT * FROM non_existing limit :limit', array(':limit' => 10)); + $this->db->execute('SELECT * FROM non_existing limit :limit', [':limit' => 10]); } /** @@ -92,7 +92,7 @@ public function testDrop() */ public function testGetTables() { - $this->assertEquals(array('date_test', 'users'), $this->db->getTables()); + $this->assertEquals(['date_test', 'users'], $this->db->getTables()); } /** @@ -166,9 +166,9 @@ public function testGetNumRows() { $this->assertEquals(1001, $this->db->getNumRows('SELECT id FROM users')); $this->assertEquals(1001, $this->db->getNumRows('SELECT id FROM users WHERE id != ?', 1337)); - $this->assertEquals(1001, $this->db->getNumRows('SELECT id FROM users WHERE id != :id', array(':id' => 1337))); - $this->assertEquals(1001, $this->db->getNumRows('SELECT id FROM users LIMIT ?', array(9999))); - $this->assertEquals(1001, $this->db->getNumRows('SELECT id FROM users LIMIT :limit', array(':limit' => 9999))); + $this->assertEquals(1001, $this->db->getNumRows('SELECT id FROM users WHERE id != :id', [':id' => 1337])); + $this->assertEquals(1001, $this->db->getNumRows('SELECT id FROM users LIMIT ?', [9999])); + $this->assertEquals(1001, $this->db->getNumRows('SELECT id FROM users LIMIT :limit', [':limit' => 9999])); } /** @@ -176,7 +176,7 @@ public function testGetNumRows() */ public function testGetEnumValues() { - $this->assertEquals(array('Y', 'N'), $this->db->getEnumValues('users', 'developer')); + $this->assertEquals(['Y', 'N'], $this->db->getEnumValues('users', 'developer')); } /** @@ -188,14 +188,14 @@ public function testGetVar() $this->assertEquals('1001', $this->db->getVar('SELECT COUNT(id) FROM users WHERE id != ?', 1337)); $this->assertEquals( '1001', - $this->db->getVar('SELECT COUNT(id) FROM users WHERE id != :id', array(':id' => 1337)) + $this->db->getVar('SELECT COUNT(id) FROM users WHERE id != :id', [':id' => 1337]) ); $this->assertEquals('1', $this->db->getVar('SELECT id FROM users ORDER BY id ASC LIMIT 1')); $this->assertEquals('1', $this->db->getVar('SELECT id FROM users ORDER BY id ASC LIMIT ?', 1)); - $this->assertEquals('1', $this->db->getVar('SELECT id FROM users ORDER BY id ASC LIMIT ?', array(1))); + $this->assertEquals('1', $this->db->getVar('SELECT id FROM users ORDER BY id ASC LIMIT ?', [1])); $this->assertEquals( '1', - $this->db->getVar('SELECT id FROM users ORDER BY id ASC LIMIT :limit', array(':limit' => 1)) + $this->db->getVar('SELECT id FROM users ORDER BY id ASC LIMIT :limit', [':limit' => 1]) ); } @@ -211,18 +211,18 @@ public function testGetPairs() ); $this->assertEquals( 10, - count($this->db->getPairs('SELECT id, username FROM users WHERE id != ? LIMIT ?', array(1337, 10))) + count($this->db->getPairs('SELECT id, username FROM users WHERE id != ? LIMIT ?', [1337, 10])) ); $this->assertEquals( 10, - count($this->db->getPairs('SELECT id, username FROM users WHERE id != :id LIMIT 10', array(':id' => 1337))) + count($this->db->getPairs('SELECT id, username FROM users WHERE id != :id LIMIT 10', [':id' => 1337])) ); $this->assertEquals( 10, count( $this->db->getPairs( 'SELECT id, username FROM users WHERE id != :id LIMIT :limit', - array(':id' => 1337, ':limit' => 10) + [':id' => 1337, ':limit' => 10] ) ) ); @@ -235,7 +235,7 @@ public function testDelete() { // delete record 1 and 1001 $this->db->delete('users', 'id = ?', 1); - $this->db->delete('users', 'id = :id', array(':id' => 1001)); + $this->db->delete('users', 'id = :id', [':id' => 1001]); // 999 records should remain $this->assertEquals(999, $this->db->getVar('SELECT COUNT(id) FROM users')); @@ -252,7 +252,7 @@ public function testUpdate() // update record $this->db->update( 'users', - array('id' => 1337, 'username' => 'Bauffman', 'email' => 'erik@bauffman.be', 'developer' => 'Y'), + ['id' => 1337, 'username' => 'Bauffman', 'email' => 'erik@bauffman.be', 'developer' => 'Y'], 'id = ?', 2 ); @@ -263,9 +263,9 @@ public function testUpdate() // update record $this->db->update( 'users', - array('id' => 1337), + ['id' => 1337], 'id = :leet AND id != :bauffman', - array(':leet' => 1337, ':bauffman' => 291) + [':leet' => 1337, ':bauffman' => 291] ); } @@ -285,7 +285,7 @@ public function testUpdateDate() public function testOptimize() { self::assertIsArray($this->db->optimize('users')); - self::assertIsArray($this->db->optimize(array('users'))); + self::assertIsArray($this->db->optimize(['users'])); } /** @@ -321,7 +321,7 @@ public function testGetRecord() ); $this->assertEquals( $data, - $this->db->getRecord('SELECT username, email, developer FROM users WHERE id = :id', array(':id' => 1337)) + $this->db->getRecord('SELECT username, email, developer FROM users WHERE id = :id', [':id' => 1337]) ); } @@ -333,7 +333,7 @@ public function testGetRecords() $this->assertEquals(100, count($this->db->getRecords('SELECT * FROM users WHERE id != ? LIMIT 100', 1337))); $this->assertEquals( 100, - count($this->db->getRecords('SELECT * FROM users WHERE id != :id LIMIT 100', array(':id' => 1337))) + count($this->db->getRecords('SELECT * FROM users WHERE id != :id LIMIT 100', [':id' => 1337])) ); } @@ -343,7 +343,7 @@ public function testGetRecords() public function testTruncate() { $this->db->truncate('users'); - $this->db->truncate(array('users')); + $this->db->truncate(['users']); $this->assertEquals(0, $this->db->getNumRows('SELECT id FROM users')); } diff --git a/spoon/tests/datagrid/SpoonDataGridTest.php b/spoon/tests/datagrid/SpoonDataGridTest.php index c95c436..65ae3fb 100644 --- a/spoon/tests/datagrid/SpoonDataGridTest.php +++ b/spoon/tests/datagrid/SpoonDataGridTest.php @@ -2,7 +2,7 @@ use PHPUnit\Framework\TestCase; -$includePath = dirname(dirname(dirname(dirname(__FILE__)))); +$includePath = dirname(__FILE__, 4); set_include_path(get_include_path() . PATH_SEPARATOR . $includePath); require_once 'spoon/spoon.php'; @@ -12,9 +12,9 @@ class SpoonDataGridTest extends TestCase public function testMain() { // data array - $array[] = array('name' => 'Davy Hellemans', 'email' => 'davy@spoon-library.be'); - $array[] = array('name' => 'Tijs Verkoyen', 'email' => 'tijs@spoon-library.be'); - $array[] = array('name' => 'Dave Lens', 'email' => 'dave@spoon-library.be'); + $array[] = ['name' => 'Davy Hellemans', 'email' => 'davy@spoon-library.be']; + $array[] = ['name' => 'Tijs Verkoyen', 'email' => 'tijs@spoon-library.be']; + $array[] = ['name' => 'Dave Lens', 'email' => 'dave@spoon-library.be']; // create source $source = new SpoonDatagridSourceArray($array); @@ -27,9 +27,9 @@ public function testMain() public function testGetTemplate() { // data array - $array[] = array('name' => 'Davy Hellemans', 'email' => 'davy@spoon-library.be'); - $array[] = array('name' => 'Tijs Verkoyen', 'email' => 'tijs@spoon-library.be'); - $array[] = array('name' => 'Dave Lens', 'email' => 'dave@spoon-library.be'); + $array[] = ['name' => 'Davy Hellemans', 'email' => 'davy@spoon-library.be']; + $array[] = ['name' => 'Tijs Verkoyen', 'email' => 'tijs@spoon-library.be']; + $array[] = ['name' => 'Dave Lens', 'email' => 'dave@spoon-library.be']; // create source $source = new SpoonDatagridSourceArray($array); diff --git a/spoon/tests/date/SpoonDateTest.php b/spoon/tests/date/SpoonDateTest.php index 1895d9c..59b472d 100644 --- a/spoon/tests/date/SpoonDateTest.php +++ b/spoon/tests/date/SpoonDateTest.php @@ -4,7 +4,7 @@ date_default_timezone_set('Europe/Brussels'); -$includePath = dirname(dirname(dirname(dirname(__FILE__)))); +$includePath = dirname(__FILE__, 4); set_include_path(get_include_path() . PATH_SEPARATOR . $includePath); require_once 'spoon/spoon.php'; diff --git a/spoon/tests/directory/SpoonDirectoryTest.php b/spoon/tests/directory/SpoonDirectoryTest.php index c6eb7da..da6470b 100644 --- a/spoon/tests/directory/SpoonDirectoryTest.php +++ b/spoon/tests/directory/SpoonDirectoryTest.php @@ -2,7 +2,7 @@ use PHPUnit\Framework\TestCase; -$includePath = dirname(dirname(dirname(dirname(__FILE__)))); +$includePath = dirname(__FILE__, 4); set_include_path(get_include_path() . PATH_SEPARATOR . $includePath); require_once 'spoon/spoon.php'; @@ -14,7 +14,7 @@ class SpoonDirectoryTest extends TestCase protected function setup(): void { // set path - $this->path = dirname(dirname(__FILE__)) . '/tmp'; + $this->path = dirname(__FILE__, 2) . '/tmp'; } public function testCopy() diff --git a/spoon/tests/feed/SpoonFeedRSSTest.php b/spoon/tests/feed/SpoonFeedRSSTest.php index 19cd09c..0ea2d6b 100644 --- a/spoon/tests/feed/SpoonFeedRSSTest.php +++ b/spoon/tests/feed/SpoonFeedRSSTest.php @@ -2,7 +2,7 @@ use PHPUnit\Framework\TestCase; -$includePath = dirname(dirname(dirname(dirname(__FILE__)))); +$includePath = dirname(__FILE__, 4); set_include_path(get_include_path() . PATH_SEPARATOR . $includePath); require_once 'spoon/spoon.php'; diff --git a/spoon/tests/file/SpoonFileTest.php b/spoon/tests/file/SpoonFileTest.php index 9113b02..a900b35 100644 --- a/spoon/tests/file/SpoonFileTest.php +++ b/spoon/tests/file/SpoonFileTest.php @@ -2,18 +2,22 @@ use PHPUnit\Framework\TestCase; -$includePath = dirname(dirname(dirname(dirname(__FILE__)))); +$includePath = dirname(__FILE__, 4); set_include_path(get_include_path() . PATH_SEPARATOR . $includePath); require_once 'spoon/spoon.php'; class SpoonFileTest extends TestCase { + private string $existingUrl; + private string $nonExistingUrl; + private string $destinationFile; + public function setup(): void { - if(!defined('TMPPATH')) define('TMPPATH', dirname(realpath(dirname(__FILE__))) . '/tmp'); + if(!defined('TMPPATH')) define('TMPPATH', dirname(realpath(__DIR__)) . '/tmp'); - $this->existingUrl = 'http://www.spoon-library.be/downloads/1.0.3/spoon-1.0.3.zip'; + $this->existingUrl = 'https://github.com/forkcms/library/archive/refs/tags/3.2.12.zip'; $this->nonExistingUrl = 'http://wowbesturleverforspoonlibrary.dev/' . time() . '.txt'; $this->destinationFile = TMPPATH . '/spoon.zip'; } diff --git a/spoon/tests/filter/SpoonFilterIsURLTest.php b/spoon/tests/filter/SpoonFilterIsURLTest.php index e3690b7..a3d0ea6 100644 --- a/spoon/tests/filter/SpoonFilterIsURLTest.php +++ b/spoon/tests/filter/SpoonFilterIsURLTest.php @@ -2,7 +2,7 @@ use PHPUnit\Framework\TestCase; -$includePath = dirname(dirname(dirname(dirname(__FILE__)))); +$includePath = dirname(__FILE__, 4); set_include_path(get_include_path() . PATH_SEPARATOR . $includePath); require_once 'spoon/spoon.php'; diff --git a/spoon/tests/filter/SpoonFilterTest.php b/spoon/tests/filter/SpoonFilterTest.php index 5df62fa..131ac71 100644 --- a/spoon/tests/filter/SpoonFilterTest.php +++ b/spoon/tests/filter/SpoonFilterTest.php @@ -2,7 +2,7 @@ use PHPUnit\Framework\TestCase; -$includePath = dirname(dirname(dirname(dirname(__FILE__)))); +$includePath = dirname(__FILE__, 4); set_include_path(get_include_path() . PATH_SEPARATOR . $includePath); require_once 'spoon/spoon.php'; @@ -13,10 +13,10 @@ public function testArrayMapRecursive() { /* without allowedKeys parameter */ // test array - $testArray = array(0 => array('string1' => 'This%20is%20a%20string'), 1 => array('string2' => 'This%20is%20a%20string')); + $testArray = [0 => ['string1' => 'This%20is%20a%20string'], 1 => ['string2' => 'This%20is%20a%20string']]; // expected result - $testResult = array(0 => array('string1' => 'This is a string'), 1 => array('string2' => 'This is a string')); + $testResult = [0 => ['string1' => 'This is a string'], 1 => ['string2' => 'This is a string']]; // perform test $this->assertEquals($testResult, SpoonFilter::arrayMapRecursive('urldecode', $testArray)); @@ -24,10 +24,10 @@ public function testArrayMapRecursive() /* with allowedKeys parameter */ // test array - $testArray = array(0 => serialize(array('string1' => 'spoon')), 1 => serialize(array('string2' => 'rocks'))); + $testArray = [0 => serialize(['string1' => 'spoon']), 1 => serialize(['string2' => 'rocks'])]; // expected result - $testResult= array(0 => 'a:1:{s:7:"string1";s:5:"spoon";}', 1 => array('string2' => 'rocks')); + $testResult= [0 => 'a:1:{s:7:"string1";s:5:"spoon";}', 1 => ['string2' => 'rocks']]; // perform test $this->assertEquals($testResult, SpoonFilter::arrayMapRecursive('unserialize', $testArray, '1')); @@ -35,22 +35,22 @@ public function testArrayMapRecursive() /* with allowedKeys parameter, depth of 4 */ // test array - $testArray = array(0 => array('array1' => array(array('spoon' => serialize('kicks'), 'serious' => serialize('ass')))), 1 => serialize(array('string2' => 'ass'))); + $testArray = [0 => ['array1' => [['spoon' => serialize('kicks'), 'serious' => serialize('ass')]]], 1 => serialize(['string2' => 'ass'])]; // expected result - $testResult = array(0 => array('array1' => array(array('spoon' => 's:5:"kicks";', 'serious' => 'ass'))), 1 => array('string2' => 'ass')); + $testResult = [0 => ['array1' => [['spoon' => 's:5:"kicks";', 'serious' => 'ass']]], 1 => ['string2' => 'ass']]; // perform test - $this->assertEquals($testResult, SpoonFilter::arrayMapRecursive('unserialize', $testArray, array('serious', '1'))); + $this->assertEquals($testResult, SpoonFilter::arrayMapRecursive('unserialize', $testArray, ['serious', '1'])); } public function testArraySortKeys() { // test array - $testArray = array(-2 => 'Davy Hellemans', 1 => 'Tijs Verkoyen', 4 => 'Dave Lens'); + $testArray = [-2 => 'Davy Hellemans', 1 => 'Tijs Verkoyen', 4 => 'Dave Lens']; // expected result - $expectedArray = array('Davy Hellemans', 'Tijs Verkoyen', 'Dave Lens'); + $expectedArray = ['Davy Hellemans', 'Tijs Verkoyen', 'Dave Lens']; // perform test $this->assertEquals($expectedArray, SpoonFilter::arraySortKeys($testArray)); @@ -62,16 +62,16 @@ public function testGetValue() $id = '1337'; $type = 'web'; $animal = 'donkey'; - $animals = array('1337', 'web', 'donkey'); + $animals = ['1337', 'web', 'donkey']; // perform tests $this->assertEquals(1337, SpoonFilter::getValue($id, null, 0, 'int')); - $this->assertEquals('web', SpoonFilter::getValue($type, array('web', 'print'), 'print')); - $this->assertEquals('whale', SpoonFilter::getValue($animal, array('whale', 'horse'), 'whale')); + $this->assertEquals('web', SpoonFilter::getValue($type, ['web', 'print'], 'print')); + $this->assertEquals('whale', SpoonFilter::getValue($animal, ['whale', 'horse'], 'whale')); $this->assertEquals('donkey', SpoonFilter::getValue($animal, null, 'whale')); - $this->assertEquals(array('1337', 'web', 'donkey'), SpoonFilter::getValue($animals, null, null, 'array')); - $this->assertEquals(array('1337', 'web'), SpoonFilter::getValue($animals, array('1337', 'web'), array('soep'), 'array')); - $this->assertEquals(array('soep'), SpoonFilter::getValue(array('blikken doos'), array('1337', 'web'), array('soep'), 'array')); + $this->assertEquals(['1337', 'web', 'donkey'], SpoonFilter::getValue($animals, null, null, 'array')); + $this->assertEquals(['1337', 'web'], SpoonFilter::getValue($animals, ['1337', 'web'], ['soep'], 'array')); + $this->assertEquals(['soep'], SpoonFilter::getValue(['blikken doos'], ['1337', 'web'], ['soep'], 'array')); } public function testHtmlentities() @@ -81,7 +81,7 @@ public function testHtmlentities() $expectedResult = 'Ik heb "géén" bananen vandaag'; // perform test - $this->assertEquals($expectedResult, SpoonFilter::htmlentities(utf8_decode($input), 'iso-8859-1')); + $this->assertEquals($expectedResult, SpoonFilter::htmlentities(mb_convert_encoding($input, 'ISO-8859-1'), 'iso-8859-1')); $this->assertEquals($expectedResult, SpoonFilter::htmlentities($input, 'utf-8')); $expectedResult = 'Ik heb "géén" bananen vandaag'; $this->assertEquals($expectedResult, SpoonFilter::htmlentities($input, null, ENT_QUOTES)); @@ -104,7 +104,7 @@ public function testHtmlentitiesDecode() $expectedResult = 'Ik heb géén bananen vandaag'; // perform test - $this->assertEquals(utf8_decode($expectedResult), SpoonFilter::htmlentitiesDecode(utf8_decode($input), 'iso-8859-1')); + $this->assertEquals(mb_convert_encoding($expectedResult, 'ISO-8859-1'), SpoonFilter::htmlentitiesDecode(mb_convert_encoding($input, 'ISO-8859-1'), 'iso-8859-1')); $this->assertEquals($expectedResult, SpoonFilter::htmlentitiesDecode($input, 'utf-8')); } @@ -116,7 +116,7 @@ public function testIsAlphabetical() $this->assertFalse(SpoonFilter::isAlphabetical('gééN')); // Simulating PHP < 5.4 behaviour - $this->assertTrue(SpoonFilter::isAlphabetical(array('a', 'b'))); + $this->assertTrue(SpoonFilter::isAlphabetical(['a', 'b'])); } public function testIsAlphaNumeric() @@ -125,7 +125,7 @@ public function testIsAlphaNumeric() $this->assertFalse(SpoonFilter::isAlphaNumeric('Johan Mayer 007')); // Simulating PHP < 5.4 behaviour - $this->assertTrue(SpoonFilter::isAlphaNumeric(array('a', 'b'))); + $this->assertTrue(SpoonFilter::isAlphaNumeric(['a', 'b'])); } public function testIsBetween() @@ -149,7 +149,7 @@ public function testIsBool() $this->assertFalse(SpoonFilter::isBool(100)); $this->assertFalse(SpoonFilter::isBool(900)); $this->assertFalse(SpoonFilter::isBool(077)); - $this->assertFalse(SpoonFilter::isBool(array())); + $this->assertFalse(SpoonFilter::isBool([])); } public function testIsDigital() @@ -157,7 +157,7 @@ public function testIsDigital() $this->assertTrue(SpoonFilter::isDigital('010192029')); $this->assertTrue(SpoonFilter::isDigital(1337)); $this->assertFalse(SpoonFilter::isDigital('I can has cheezeburger')); - $this->assertFalse(SpoonFilter::isDigital(array())); + $this->assertFalse(SpoonFilter::isDigital([])); } public function testIsEmail() @@ -168,8 +168,8 @@ public function testIsEmail() $this->assertTrue(SpoonFilter::isEmail('erik.bauffman@spoon-library.be')); $this->assertTrue(SpoonFilter::isEmail('a.osterhaus@erasmusnc.nl')); $this->assertTrue(SpoonFilter::isEmail('asmonto@umich.edu')); - $this->assertFalse(SpoonFilter::isEmail(array())); - $this->assertFalse(SpoonFilter::isEmail(array('foo@example.com'))); + $this->assertFalse(SpoonFilter::isEmail([])); + $this->assertFalse(SpoonFilter::isEmail(['foo@example.com'])); } public function testIsEven() @@ -181,8 +181,8 @@ public function testIsEven() // I don't know man, semantically speaking, this bull shit, but it does // adhere to PHP's idiosyncratic casting rules. - $this->assertTrue(SpoonFilter::isEven(array())); - $this->assertFalse(SpoonFilter::isEven(array(2))); + $this->assertTrue(SpoonFilter::isEven([])); + $this->assertFalse(SpoonFilter::isEven([2])); } public function testIsFilename() @@ -192,7 +192,7 @@ public function testIsFilename() $this->assertFalse(SpoonFilter::isFilename('/Users/bauffman/Desktop/test.txt')); // Simulating PHP < 5.4 behaviour - $this->assertTrue(SpoonFilter::isFilename(array())); + $this->assertTrue(SpoonFilter::isFilename([])); } public function testIsFloat() @@ -214,7 +214,7 @@ public function testIsFloat() $this->assertTrue(SpoonFilter::isFloat('65.00')); $this->assertTrue(SpoonFilter::isFloat(65.010, true)); $this->assertTrue(SpoonFilter::isFloat('65.010', true)); - $this->assertFalse(SpoonFilter::isFloat(array())); + $this->assertFalse(SpoonFilter::isFloat([])); } public function testIsGreaterThan() @@ -224,7 +224,7 @@ public function testIsGreaterThan() $this->assertTrue(SpoonFilter::isGreaterThan(-1, 10)); $this->assertFalse(SpoonFilter::isGreaterThan(1, -10)); $this->assertFalse(SpoonFilter::isGreaterThan(0, 0)); - $this->assertTrue(SpoonFilter::isGreaterThan(array(), array(1))); + $this->assertTrue(SpoonFilter::isGreaterThan([], [1])); } public function testIsInteger() @@ -235,7 +235,7 @@ public function testIsInteger() $this->assertTrue(SpoonFilter::isInteger(-1234567890)); $this->assertFalse(SpoonFilter::isInteger(1.337)); $this->assertFalse(SpoonFilter::isInteger(-1.337)); - $this->assertFalse(SpoonFilter::isInteger(array())); + $this->assertFalse(SpoonFilter::isInteger([])); } @@ -248,14 +248,14 @@ public function testIsInternalReferrer() // new referrer $_SERVER['HTTP_REFERER'] = 'http://www.spoon-library.com/about-us'; $_SERVER['HTTP_HOST'] = 'spoon-library.com'; - $this->assertTrue(SpoonFilter::isInternalReferrer(array('spoon-library.com'))); + $this->assertTrue(SpoonFilter::isInternalReferrer(['spoon-library.com'])); // multiple domains - $this->assertTrue(SpoonFilter::isInternalReferrer(array('docs.spoon-library.com', 'blog.spoon-library.com', 'spoon-library.com'))); + $this->assertTrue(SpoonFilter::isInternalReferrer(['docs.spoon-library.com', 'blog.spoon-library.com', 'spoon-library.com'])); // incorrect! - $this->assertFalse(SpoonFilter::isInternalReferrer(array('rotten.com'))); - $this->assertFalse(SpoonFilter::isInternalReferrer(array('rotten.com', 'rotn.com'))); + $this->assertFalse(SpoonFilter::isInternalReferrer(['rotten.com'])); + $this->assertFalse(SpoonFilter::isInternalReferrer(['rotten.com', 'rotn.com'])); } public function testIsIP() @@ -263,7 +263,7 @@ public function testIsIP() $this->assertTrue(SpoonFilter::isIp('127.0.0.1')); $this->assertTrue(SpoonFilter::isIp('192.168.1.101')); $this->assertFalse(SpoonFilter::isIp('kfsl')); - $this->assertFalse(SpoonFilter::isIp(array())); + $this->assertFalse(SpoonFilter::isIp([])); } public function testIsMaximum() @@ -276,14 +276,14 @@ public function testIsMaximum() // Again, showing the downright dangerous implications of casting as a // defensive programming technique. - $this->assertTrue(SpoonFilter::isMaximum(array(), array())); - $this->assertTrue(SpoonFilter::isMaximum(array(1), array())); - $this->assertFalse(SpoonFilter::isMaximum(array(), array(1))); - $this->assertFalse(SpoonFilter::isMaximum(array(), 10)); - $this->assertTrue(SpoonFilter::isMaximum(array(), 0)); - $this->assertTrue(SpoonFilter::isMaximum(array(1), 0)); - $this->assertTrue(SpoonFilter::isMaximum(array(1), 1)); - $this->assertFalse(SpoonFilter::isMaximum(array(1), 2)); + $this->assertTrue(SpoonFilter::isMaximum([], [])); + $this->assertTrue(SpoonFilter::isMaximum([1], [])); + $this->assertFalse(SpoonFilter::isMaximum([], [1])); + $this->assertFalse(SpoonFilter::isMaximum([], 10)); + $this->assertTrue(SpoonFilter::isMaximum([], 0)); + $this->assertTrue(SpoonFilter::isMaximum([1], 0)); + $this->assertTrue(SpoonFilter::isMaximum([1], 1)); + $this->assertFalse(SpoonFilter::isMaximum([1], 2)); } public function testIsMaximumCharacters() @@ -291,7 +291,7 @@ public function testIsMaximumCharacters() $string = 'Ik heb er géén gedacht van'; $this->assertTrue(SpoonFilter::isMaximumCharacters(26, $string, 'utf-8')); $this->assertFalse(SpoonFilter::isMaximumCharacters(10, $string, 'utf-8')); - $this->assertTrue(SpoonFilter::isMaximumCharacters(26, utf8_decode($string), 'iso-8859-1')); + $this->assertTrue(SpoonFilter::isMaximumCharacters(26, mb_convert_encoding($string, 'ISO-8859-1'), 'iso-8859-1')); } public function testIsMinimum() @@ -308,7 +308,7 @@ public function testIsMinimumCharacters() $string = 'Ik heb er géén gedacht van'; $this->assertTrue(SpoonFilter::isMinimumCharacters(10, $string, 'utf-8')); $this->assertFalse(SpoonFilter::isMinimumCharacters(30, $string, 'utf-8')); - $this->assertTrue(SpoonFilter::isMinimumCharacters(10, utf8_decode($string), 'iso-8859-1')); + $this->assertTrue(SpoonFilter::isMinimumCharacters(10, mb_convert_encoding($string, 'ISO-8859-1'), 'iso-8859-1')); } public function testIsNumeric() @@ -340,7 +340,7 @@ public function testIsString() $this->assertTrue(SpoonFilter::isString('This should qualify as a string.')); // Simulating (string) casting behaviour in PHP < 5.4 - $this->assertTrue(SpoonFilter::isString(array())); + $this->assertTrue(SpoonFilter::isString([])); } public function testIsValidAgainstRegexp() @@ -365,7 +365,7 @@ public function testToCamelCase() public function testReplaceURLsWithAnchors() { - $tlds = array('ac', 'ad', 'ae', 'aero', 'af', 'ag', 'ai', 'al', 'am', 'an', 'ao', 'aq', 'ar', 'arpa', 'as', 'asia', 'at', 'au', 'aw', 'ax', 'az', + $tlds = ['ac', 'ad', 'ae', 'aero', 'af', 'ag', 'ai', 'al', 'am', 'an', 'ao', 'aq', 'ar', 'arpa', 'as', 'asia', 'at', 'au', 'aw', 'ax', 'az', 'ba', 'bb', 'bd' ,'be', 'bf', 'bg', 'bh', 'bi', 'biz', 'bj', 'bm', 'bn', 'bo', 'br', 'bs', 'bt', 'bv', 'bw', 'by' ,'bz', 'ca', 'cat', 'cc' ,'cd', 'cf', 'cg', 'ch', 'ci', 'ck', 'cl', 'cm', 'cn', 'co', 'com', 'coop', 'cr', 'cu', 'cv', 'cx', 'cy', 'cz', 'de', 'dj', 'dk', 'dm', 'do', 'dz', @@ -389,7 +389,7 @@ public function testReplaceURLsWithAnchors() 'va', 'vc', 've', 'vg', 'vi', 'vn', 'vu', 'wf', 'ws', 'ye', 'yt', 'yu', - 'za', 'zm', 'zw'); + 'za', 'zm', 'zw']; foreach($tlds as $tld) { diff --git a/spoon/tests/form/SpoonFileFieldTest.php b/spoon/tests/form/SpoonFileFieldTest.php index 1077ccf..fbcf581 100644 --- a/spoon/tests/form/SpoonFileFieldTest.php +++ b/spoon/tests/form/SpoonFileFieldTest.php @@ -2,7 +2,7 @@ use PHPUnit\Framework\TestCase; -$includePath = dirname(dirname(dirname(dirname(__FILE__)))); +$includePath = dirname(__FILE__, 4); set_include_path(get_include_path() . PATH_SEPARATOR . $includePath); require_once 'spoon/spoon.php'; @@ -36,8 +36,8 @@ public function testAttributes() { $this->filePDF->setAttribute('rel', 'bauffman.jpg'); $this->assertEquals('bauffman.jpg', $this->filePDF->getAttribute('rel')); - $this->filePDF->setAttributes(array('id' => 'specialID')); - $this->assertEquals(array('id' => 'specialID', 'name' => 'pdf', 'class' => 'inputFilefield', 'rel' => 'bauffman.jpg'), $this->filePDF->getAttributes()); + $this->filePDF->setAttributes(['id' => 'specialID']); + $this->assertEquals(['id' => 'specialID', 'name' => 'pdf', 'class' => 'inputFilefield', 'rel' => 'bauffman.jpg'], $this->filePDF->getAttributes()); } public function testGetExtension() @@ -65,8 +65,8 @@ public function testGetFileSize() public function testIsAllowedExtension() { $_POST['form'] = 'filefield'; - $this->assertEquals(true, $this->filePDF->isAllowedExtension(array('jpg', 'pdf', 'jpeg'))); - $this->assertEquals(false, $this->filePDF->isAllowedExtension(array('xpdf'))); + $this->assertEquals(true, $this->filePDF->isAllowedExtension(['jpg', 'pdf', 'jpeg'])); + $this->assertEquals(false, $this->filePDF->isAllowedExtension(['xpdf'])); } public function testIsFileName() diff --git a/spoon/tests/form/SpoonFormButtonTest.php b/spoon/tests/form/SpoonFormButtonTest.php index d399752..71d8224 100644 --- a/spoon/tests/form/SpoonFormButtonTest.php +++ b/spoon/tests/form/SpoonFormButtonTest.php @@ -2,7 +2,7 @@ use PHPUnit\Framework\TestCase; -$includePath = dirname(dirname(dirname(dirname(__FILE__)))); +$includePath = dirname(__FILE__, 4); set_include_path(get_include_path() . PATH_SEPARATOR . $includePath); require_once 'spoon/spoon.php'; @@ -43,11 +43,11 @@ public function testAttributes() $this->assertEquals('bauffman.jpg', $this->btnSubmit->getAttribute('rel')); $this->assertEquals('bauffman.jpg', $this->btnReset->getAttribute('rel')); $this->assertEquals('bauffman.jpg', $this->btnSpecial->getAttribute('rel')); - $this->btnSubmit->setAttributes(array('id' => 'specialID')); - $this->btnReset->setAttributes(array('id' => 'specialID')); - $this->btnSpecial->setAttributes(array('id' => 'specialID')); - $this->assertEquals(array('id' => 'specialID', 'name' => 'submit', 'class' => 'inputButton', 'rel' => 'bauffman.jpg'), $this->btnSubmit->getAttributes()); - $this->assertEquals(array('id' => 'specialID', 'name' => 'reset', 'class' => 'inputButton', 'rel' => 'bauffman.jpg'), $this->btnReset->getAttributes()); - $this->assertEquals(array('id' => 'specialID', 'name' => 'special', 'class' => 'inputButton', 'rel' => 'bauffman.jpg'), $this->btnSpecial->getAttributes()); + $this->btnSubmit->setAttributes(['id' => 'specialID']); + $this->btnReset->setAttributes(['id' => 'specialID']); + $this->btnSpecial->setAttributes(['id' => 'specialID']); + $this->assertEquals(['id' => 'specialID', 'name' => 'submit', 'class' => 'inputButton', 'rel' => 'bauffman.jpg'], $this->btnSubmit->getAttributes()); + $this->assertEquals(['id' => 'specialID', 'name' => 'reset', 'class' => 'inputButton', 'rel' => 'bauffman.jpg'], $this->btnReset->getAttributes()); + $this->assertEquals(['id' => 'specialID', 'name' => 'special', 'class' => 'inputButton', 'rel' => 'bauffman.jpg'], $this->btnSpecial->getAttributes()); } } diff --git a/spoon/tests/form/SpoonFormCheckboxTest.php b/spoon/tests/form/SpoonFormCheckboxTest.php index a45fbc9..ecd0912 100644 --- a/spoon/tests/form/SpoonFormCheckboxTest.php +++ b/spoon/tests/form/SpoonFormCheckboxTest.php @@ -2,7 +2,7 @@ use PHPUnit\Framework\TestCase; -$includePath = dirname(dirname(dirname(dirname(__FILE__)))); +$includePath = dirname(__FILE__, 4); set_include_path(get_include_path() . PATH_SEPARATOR . $includePath); require_once 'spoon/spoon.php'; @@ -33,7 +33,7 @@ public function testGetChecked() $this->assertFalse($this->chkAgree->getChecked()); $_POST['form'] = 'checkbox'; - $_POST['agree'] = array('foo', 'bar'); + $_POST['agree'] = ['foo', 'bar']; $this->assertFalse($this->chkAgree->getChecked()); } @@ -41,8 +41,8 @@ public function testAttributes() { $this->chkAgree->setAttribute('rel', 'bauffman.jpg'); $this->assertEquals('bauffman.jpg', $this->chkAgree->getAttribute('rel')); - $this->chkAgree->setAttributes(array('id' => 'specialID')); - $this->assertEquals(array('id' => 'specialID', 'name' => 'agree', 'class' => 'inputCheckbox', 'rel' => 'bauffman.jpg'), $this->chkAgree->getAttributes()); + $this->chkAgree->setAttributes(['id' => 'specialID']); + $this->assertEquals(['id' => 'specialID', 'name' => 'agree', 'class' => 'inputCheckbox', 'rel' => 'bauffman.jpg'], $this->chkAgree->getAttributes()); } public function testGetValue() @@ -52,7 +52,7 @@ public function testGetValue() $_POST['agree'] = '1'; $this->assertTrue($this->chkAgree->getValue()); - $_POST['agree'] = array('foo', 'bar'); + $_POST['agree'] = ['foo', 'bar']; $this->assertFalse($this->chkAgree->getValue()); } @@ -64,7 +64,7 @@ public function testIsFilled() $_POST['agree'] = '1'; $this->assertTrue($this->chkAgree->isFilled()); - $_POST['agree'] = array('foo', 'bar'); + $_POST['agree'] = ['foo', 'bar']; $this->assertFalse($this->chkAgree->isFilled()); } } diff --git a/spoon/tests/form/SpoonFormDateTest.php b/spoon/tests/form/SpoonFormDateTest.php index b7b6ecb..3e18276 100644 --- a/spoon/tests/form/SpoonFormDateTest.php +++ b/spoon/tests/form/SpoonFormDateTest.php @@ -4,7 +4,7 @@ date_default_timezone_set('Europe/Brussels'); -$includePath = dirname(dirname(dirname(dirname(__FILE__)))); +$includePath = dirname(__FILE__, 4); set_include_path(get_include_path() . PATH_SEPARATOR . $includePath); require_once 'spoon/spoon.php'; @@ -48,8 +48,8 @@ public function testAttributes() { $this->txtDate->setAttribute('rel', 'bauffman.jpg'); $this->assertEquals('bauffman.jpg', $this->txtDate->getAttribute('rel')); - $this->txtDate->setAttributes(array('id' => 'specialID')); - $this->assertEquals(array('id' => 'specialID', 'name' => 'date','maxlength' => 10, 'class' => 'inputDatefield', 'rel' => 'bauffman.jpg', 'data-mask' => 'dd/mm/yy'), $this->txtDate->getAttributes()); + $this->txtDate->setAttributes(['id' => 'specialID']); + $this->assertEquals(['id' => 'specialID', 'name' => 'date','maxlength' => 10, 'class' => 'inputDatefield', 'rel' => 'bauffman.jpg', 'data-mask' => 'dd/mm/yy'], $this->txtDate->getAttributes()); } public function testIsFilled() @@ -57,7 +57,7 @@ public function testIsFilled() $this->assertFalse($this->txtDate->isFilled()); $_POST['date'] = '12/10/2009'; $this->assertTrue($this->txtDate->isFilled()); - $_POST['date'] = array('foo', 'bar'); + $_POST['date'] = ['foo', 'bar']; $this->assertTrue($this->txtDate->isFilled()); } @@ -70,7 +70,7 @@ public function testIsValid() $this->assertTrue($this->txtDate->isValid()); $_POST['date'] = '31/04/2009'; $this->assertFalse($this->txtDate->isValid()); - $_POST['date'] = array('foo', 'bar'); + $_POST['date'] = ['foo', 'bar']; $this->assertFalse($this->txtDate->isValid()); } @@ -82,7 +82,7 @@ public function testGetTimestamp() $this->assertEquals('12/11/2009 12:13:14', date('d/m/Y H:i:s', $this->txtDate->getTimestamp(null, 11, null, 12, 13, 14))); $this->assertEquals('25/10/2009 12:13:14', date('d/m/Y H:i:s', $this->txtDate->getTimestamp(null, null, 25, 12, 13, 14))); - $_POST['date'] = array('foo', 'bar'); + $_POST['date'] = ['foo', 'bar']; $this->assertEquals(date('Y-m-d H:i:s'), date('Y-m-d H:i:s', $this->txtDate->getTimestamp())); } @@ -92,13 +92,13 @@ public function testGetValue() $_POST['date'] = '12/10/2009'; $this->assertEquals('12/10/2009', $this->txtDate->getValue()); - $_POST['date'] = array('foo', 'bar'); + $_POST['date'] = ['foo', 'bar']; $this->assertEquals('Array', $this->txtDate->getValue()); } public function testDateFormatsLong() { - $formats = Array( + $formats = [ 'j F Y', 'D j F Y', 'l j F Y', @@ -113,7 +113,7 @@ public function testDateFormatsLong() 'F d, Y', 'D F d, Y', 'l F d, Y', - ); + ]; $this->loopOverFormats($formats); } @@ -140,7 +140,7 @@ private function loopOverFormats(array $formats) public function testDateFormatsShort() { - $formats = Array( + $formats = [ 'j/n/Y', 'j-n-Y', 'j.n.Y', @@ -165,7 +165,7 @@ public function testDateFormatsShort() 'm/d/y', 'm-d-y', 'm.d.y', - ); + ]; $this->loopOverFormats($formats); } diff --git a/spoon/tests/form/SpoonFormDropdownTest.php b/spoon/tests/form/SpoonFormDropdownTest.php index 040e75f..4b49472 100644 --- a/spoon/tests/form/SpoonFormDropdownTest.php +++ b/spoon/tests/form/SpoonFormDropdownTest.php @@ -2,7 +2,7 @@ use PHPUnit\Framework\TestCase; -$includePath = dirname(dirname(dirname(dirname(__FILE__)))); +$includePath = dirname(__FILE__, 4); set_include_path(get_include_path() . PATH_SEPARATOR . $includePath); require_once 'spoon/spoon.php'; @@ -22,11 +22,11 @@ class SpoonFormDropdownTest extends TestCase public function setup(): void { $this->frm = new SpoonForm('dropdown'); - $this->ddmSingle = new SpoonFormDropdown('single', array(1 => 'Davy Hellemans', 'Tys Verkoyen', 'Dave Lens')); - $this->ddmMultiple = new SpoonFormDropdown('multiple', array(1 => 'Swimming', 'Running', 'Cycling', 'Boxing', 'Slackin'), null, true); - $this->ddmOptGroupSingle = new SpoonFormDropdown('optgroup_single', array('foo', 123 => 'bar', 'foobar' => array('foo', 'baz'))); - $this->ddmOptGroupMultiple = new SpoonFormDropdown('optgroup_multiple', array('foo', 123 => 'bar', 'foobar' => array('foo', 'baz')), null, true); - $this->ddmDefaultElement = new SpoonFormDropdown('default_element', array(1 => 'Davy Hellemans')); + $this->ddmSingle = new SpoonFormDropdown('single', [1 => 'Davy Hellemans', 'Tys Verkoyen', 'Dave Lens']); + $this->ddmMultiple = new SpoonFormDropdown('multiple', [1 => 'Swimming', 'Running', 'Cycling', 'Boxing', 'Slackin'], null, true); + $this->ddmOptGroupSingle = new SpoonFormDropdown('optgroup_single', ['foo', 123 => 'bar', 'foobar' => ['foo', 'baz']]); + $this->ddmOptGroupMultiple = new SpoonFormDropdown('optgroup_multiple', ['foo', 123 => 'bar', 'foobar' => ['foo', 'baz']], null, true); + $this->ddmDefaultElement = new SpoonFormDropdown('default_element', [1 => 'Davy Hellemans']); $this->ddmDefaultElement->setDefaultElement('Baz', 1337); $this->frm->add($this->ddmSingle, $this->ddmMultiple, $this->ddmOptGroupSingle, $this->ddmOptGroupMultiple, $this->ddmDefaultElement); } @@ -36,26 +36,26 @@ public function testAttributes() // single dropdown $this->ddmSingle->setAttribute('rel', 'bauffman.jpg'); $this->assertEquals('bauffman.jpg', $this->ddmSingle->getAttribute('rel')); - $this->ddmSingle->setAttributes(array('id' => 'specialID')); - $this->assertEquals(array('id' => 'specialID', 'name' => 'single', 'class' => 'inputDropdown', 'size' => 1, 'rel' => 'bauffman.jpg'), $this->ddmSingle->getAttributes()); + $this->ddmSingle->setAttributes(['id' => 'specialID']); + $this->assertEquals(['id' => 'specialID', 'name' => 'single', 'class' => 'inputDropdown', 'size' => 1, 'rel' => 'bauffman.jpg'], $this->ddmSingle->getAttributes()); // single dropdown (optgroups) $this->ddmOptGroupSingle->setAttribute('rel', 'bauffman.jpg'); $this->assertEquals('bauffman.jpg', $this->ddmOptGroupSingle->getAttribute('rel')); - $this->ddmOptGroupSingle->setAttributes(array('id' => 'specialID')); - $this->assertEquals(array('id' => 'specialID', 'name' => 'optgroup_single', 'class' => 'inputDropdown', 'size' => 1, 'rel' => 'bauffman.jpg'), $this->ddmOptGroupSingle->getAttributes()); + $this->ddmOptGroupSingle->setAttributes(['id' => 'specialID']); + $this->assertEquals(['id' => 'specialID', 'name' => 'optgroup_single', 'class' => 'inputDropdown', 'size' => 1, 'rel' => 'bauffman.jpg'], $this->ddmOptGroupSingle->getAttributes()); // multiple dropdown $this->ddmMultiple->setAttribute('rel', 'bauffman.jpg'); $this->assertEquals('bauffman.jpg', $this->ddmMultiple->getAttribute('rel')); - $this->ddmMultiple->setAttributes(array('id' => 'specialID')); - $this->assertEquals(array('id' => 'specialID', 'name' => 'multiple', 'class' => 'inputDropdown', 'rel' => 'bauffman.jpg'), $this->ddmMultiple->getAttributes()); + $this->ddmMultiple->setAttributes(['id' => 'specialID']); + $this->assertEquals(['id' => 'specialID', 'name' => 'multiple', 'class' => 'inputDropdown', 'rel' => 'bauffman.jpg'], $this->ddmMultiple->getAttributes()); // multiple dropdown (optgroups) $this->ddmOptGroupMultiple->setAttribute('rel', 'bauffman.jpg'); $this->assertEquals('bauffman.jpg', $this->ddmOptGroupMultiple->getAttribute('rel')); - $this->ddmOptGroupMultiple->setAttributes(array('id' => 'specialID')); - $this->assertEquals(array('id' => 'specialID', 'name' => 'optgroup_multiple', 'class' => 'inputDropdown', 'rel' => 'bauffman.jpg'), $this->ddmOptGroupMultiple->getAttributes()); + $this->ddmOptGroupMultiple->setAttributes(['id' => 'specialID']); + $this->assertEquals(['id' => 'specialID', 'name' => 'optgroup_multiple', 'class' => 'inputDropdown', 'rel' => 'bauffman.jpg'], $this->ddmOptGroupMultiple->getAttributes()); } public function testIsFilled() @@ -75,7 +75,7 @@ public function testIsFilled() $this->assertFalse($this->ddmSingle->isFilled()); // arrays - $_POST['single'] = array('foo', 'bar'); + $_POST['single'] = ['foo', 'bar']; $this->assertFalse($this->ddmSingle->isFilled()); // single dropdown (optgroups) @@ -95,35 +95,35 @@ public function testIsFilled() // multiple dropdown $_POST['multiple'] = []; $this->assertFalse($this->ddmMultiple->isFilled()); - $_POST['multiple'] = array('1', '2'); + $_POST['multiple'] = ['1', '2']; $this->assertTrue($this->ddmMultiple->isFilled()); - $_POST['multiple'] = array('1336', '1337', '1338'); + $_POST['multiple'] = ['1336', '1337', '1338']; $this->assertFalse($this->ddmMultiple->isFilled()); - $_POST['multiple'] = array('1337', 1); + $_POST['multiple'] = ['1337', 1]; $this->assertTrue($this->ddmMultiple->isFilled()); // default element (multiple) $this->ddmMultiple->setDefaultElement('', '1337'); $_POST['multiple'] = 'nothing'; $this->assertFalse($this->ddmMultiple->isFilled()); - $_POST['multiple'] = array('1337'); + $_POST['multiple'] = ['1337']; $this->assertTrue($this->ddmMultiple->isFilled()); // multiple dropdown (optgroups) $_POST['optgroup_multiple'] = []; $this->assertFalse($this->ddmOptGroupMultiple->isFilled()); - $_POST['optgroup_multiple'] = array('0', '1'); + $_POST['optgroup_multiple'] = ['0', '1']; $this->assertTrue($this->ddmOptGroupMultiple->isFilled()); - $_POST['optgroup_multiple'] = array('1336', '1337', '1338'); + $_POST['optgroup_multiple'] = ['1336', '1337', '1338']; $this->assertFalse($this->ddmOptGroupMultiple->isFilled()); - $_POST['optgroup_multiple'] = array('1337', 1); + $_POST['optgroup_multiple'] = ['1337', 1]; $this->assertTrue($this->ddmOptGroupMultiple->isFilled()); // default element (multiple & optgroups) $this->ddmOptGroupMultiple->setDefaultElement('', '1337'); $_POST['optgroup_multiple'] = 'nothing'; $this->assertFalse($this->ddmOptGroupMultiple->isFilled()); - $_POST['optgroup_multiple'] = array('1337'); + $_POST['optgroup_multiple'] = ['1337']; $this->assertTrue($this->ddmOptGroupMultiple->isFilled()); } @@ -131,15 +131,15 @@ public function testGetValue() { $_POST['form'] = 'dropdown'; $_POST['single'] = '1'; - $_POST['multiple'] = array('1', '2', '3'); + $_POST['multiple'] = ['1', '2', '3']; $_POST['optgroup_single'] = '123'; - $_POST['optgroup_multiple'] = array('0', '123'); + $_POST['optgroup_multiple'] = ['0', '123']; $this->assertEquals($_POST['single'], $this->ddmSingle->getValue()); $this->assertEquals($_POST['optgroup_single'], $this->ddmOptGroupSingle->getValue()); $this->assertEquals($_POST['multiple'], $this->ddmMultiple->getValue()); $this->assertEquals($_POST['optgroup_multiple'], $this->ddmOptGroupMultiple->getValue()); - $_POST['single'] = array('foo', 'bar'); + $_POST['single'] = ['foo', 'bar']; $this->assertNull($this->ddmSingle->getValue()); } diff --git a/spoon/tests/form/SpoonFormHiddenTest.php b/spoon/tests/form/SpoonFormHiddenTest.php index ab714da..1db897a 100644 --- a/spoon/tests/form/SpoonFormHiddenTest.php +++ b/spoon/tests/form/SpoonFormHiddenTest.php @@ -2,7 +2,7 @@ use PHPUnit\Framework\TestCase; -$includePath = dirname(dirname(dirname(dirname(__FILE__)))); +$includePath = dirname(__FILE__, 4); set_include_path(get_include_path() . PATH_SEPARATOR . $includePath); require_once 'spoon/spoon.php'; @@ -30,8 +30,8 @@ public function testAttributes() { $this->hidHidden->setAttribute('rel', 'bauffman.jpg'); $this->assertEquals('bauffman.jpg', $this->hidHidden->getAttribute('rel')); - $this->hidHidden->setAttributes(array('id' => 'specialID')); - $this->assertEquals(array('id' => 'specialID', 'name' => 'hidden', 'rel' => 'bauffman.jpg'), $this->hidHidden->getAttributes()); + $this->hidHidden->setAttributes(['id' => 'specialID']); + $this->assertEquals(['id' => 'specialID', 'name' => 'hidden', 'rel' => 'bauffman.jpg'], $this->hidHidden->getAttributes()); } public function testIsFilled() @@ -39,7 +39,7 @@ public function testIsFilled() $this->assertEquals(false, $this->hidHidden->isFilled()); $_POST['hidden'] = 'I am not empty'; $this->assertTrue($this->hidHidden->isFilled()); - $_POST['hidden'] = array('foo', 'bar'); + $_POST['hidden'] = ['foo', 'bar']; $this->assertTrue($this->hidHidden->isFilled()); } @@ -48,7 +48,7 @@ public function testGetValue() $_POST['form'] = 'hiddenfield'; $_POST['hidden'] = 'But I am le tired'; $this->assertEquals($_POST['hidden'], $this->hidHidden->getValue()); - $_POST['hidden'] = array('foo', 'bar'); + $_POST['hidden'] = ['foo', 'bar']; $this->assertEquals('Array', $this->hidHidden->getValue()); } diff --git a/spoon/tests/form/SpoonFormMultiCheckBoxTest.php b/spoon/tests/form/SpoonFormMultiCheckBoxTest.php index 90f9de9..6c8b4d1 100644 --- a/spoon/tests/form/SpoonFormMultiCheckBoxTest.php +++ b/spoon/tests/form/SpoonFormMultiCheckBoxTest.php @@ -2,7 +2,7 @@ use PHPUnit\Framework\TestCase; -$includePath = dirname(dirname(dirname(dirname(__FILE__)))); +$includePath = dirname(__FILE__, 4); set_include_path(get_include_path() . PATH_SEPARATOR . $includePath); require_once 'spoon/spoon.php'; @@ -22,28 +22,28 @@ class SpoonFormMultiCheckBoxTest extends TestCase public function setup(): void { $this->frm = new SpoonForm('multicheckbox'); - $hobbies[] = array('label' => 'Swimming', 'value' => 10); - $hobbies[] = array('label' => 'Cycling', 'value' => 20, 'attributes' => array('rel' => 'bauffman.jpg')); - $hobbies[] = array('label' => 'Running', 'value' => 30); - $this->chkHobbies = new SpoonFormMultiCheckbox('hobbies', $hobbies, array(10, 20)); + $hobbies[] = ['label' => 'Swimming', 'value' => 10]; + $hobbies[] = ['label' => 'Cycling', 'value' => 20, 'attributes' => ['rel' => 'bauffman.jpg']]; + $hobbies[] = ['label' => 'Running', 'value' => 30]; + $this->chkHobbies = new SpoonFormMultiCheckbox('hobbies', $hobbies, [10, 20]); $this->frm->add($this->chkHobbies); } public function testGetChecked() { - $this->assertEquals(array('10', '20'), $this->chkHobbies->getChecked()); + $this->assertEquals(['10', '20'], $this->chkHobbies->getChecked()); } public function testIsFilled() { $this->assertFalse($this->chkHobbies->isFilled()); - $_POST['hobbies'] = array('bimbo', 'tramp'); + $_POST['hobbies'] = ['bimbo', 'tramp']; $this->assertFalse($this->chkHobbies->isFilled()); $_POST['form'] = 'multicheckbox'; $this->assertFalse($this->chkHobbies->isFilled()); - $_POST['hobbies'] = array(20); + $_POST['hobbies'] = [20]; $this->assertTrue($this->chkHobbies->isFilled()); - $_POST['hobbies'] = array(20, 'bimbo', 'tramp'); + $_POST['hobbies'] = [20, 'bimbo', 'tramp']; $this->assertTrue($this->chkHobbies->isFilled()); $_POST['hobbies'] = 'foobar'; $this->assertFalse($this->chkHobbies->isFilled()); @@ -52,46 +52,46 @@ public function testIsFilled() public function testGetValue() { $_POST['form'] = 'multicheckbox'; - $this->assertEquals(array(), $this->chkHobbies->getValue()); - $_POST['hobbies'] = array('bimbo', 'tramp'); - $this->assertEquals(array(), $this->chkHobbies->getValue()); - $_POST['hobbies'] = array('10'); - $this->assertEquals(array('10'), $this->chkHobbies->getValue()); - $_POST['hobbies'] = array('10', 'bimbo', 'tramp'); - $this->assertEquals(array('10'), $this->chkHobbies->getValue()); - $_POST['hobbies'] = array('bimbo', 'tramp', '10', '30'); - $this->assertEquals(array('10', '30'), $this->chkHobbies->getValue()); + $this->assertEquals([], $this->chkHobbies->getValue()); + $_POST['hobbies'] = ['bimbo', 'tramp']; + $this->assertEquals([], $this->chkHobbies->getValue()); + $_POST['hobbies'] = ['10']; + $this->assertEquals(['10'], $this->chkHobbies->getValue()); + $_POST['hobbies'] = ['10', 'bimbo', 'tramp']; + $this->assertEquals(['10'], $this->chkHobbies->getValue()); + $_POST['hobbies'] = ['bimbo', 'tramp', '10', '30']; + $this->assertEquals(['10', '30'], $this->chkHobbies->getValue()); $this->chkHobbies->setAllowExternalData(true); - $this->assertEquals(array('bimbo', 'tramp', '10', '30'), $this->chkHobbies->getValue()); + $this->assertEquals(['bimbo', 'tramp', '10', '30'], $this->chkHobbies->getValue()); $_POST['hobbies'] = 'foobar'; - $this->assertEquals(array(), $this->chkHobbies->getValue()); + $this->assertEquals([], $this->chkHobbies->getValue()); } public function testNotSupplyingCorrectFormatThrowsException() { - $values = array('12' => 'aaa', '132' => 'bbb', '32' => 'ccc'); + $values = ['12' => 'aaa', '132' => 'bbb', '32' => 'ccc']; $this->expectException('SpoonFormException'); $c = new SpoonFormMultiCheckbox('test', $values); } public function testNotSupplyingLabelThrowsException() { - $values = array( - array('value' => 'aaa'), - array('value' => 'bbb'), - array('value' => 'ccc') - ); + $values = [ + ['value' => 'aaa'], + ['value' => 'bbb'], + ['value' => 'ccc'] + ]; $this->expectException('SpoonFormException'); $c = new SpoonFormMultiCheckbox('test', $values); } public function testNotSupplyingValueThrowsException() { - $values = array( - array('label' => 'aaa'), - array('label' => 'bbb'), - array('label' => 'ccc') - ); + $values = [ + ['label' => 'aaa'], + ['label' => 'bbb'], + ['label' => 'ccc'] + ]; $this->expectException('SpoonFormException'); $c = new SpoonFormMultiCheckbox('test', $values); } diff --git a/spoon/tests/form/SpoonFormPasswordTest.php b/spoon/tests/form/SpoonFormPasswordTest.php index 35c85d1..f0c7426 100644 --- a/spoon/tests/form/SpoonFormPasswordTest.php +++ b/spoon/tests/form/SpoonFormPasswordTest.php @@ -2,7 +2,7 @@ use PHPUnit\Framework\TestCase; -$includePath = dirname(dirname(dirname(dirname(__FILE__)))); +$includePath = dirname(__FILE__, 4); set_include_path(get_include_path() . PATH_SEPARATOR . $includePath); require_once 'spoon/spoon.php'; @@ -45,8 +45,8 @@ public function testAttributes() { $this->txtPassword->setAttribute('rel', 'bauffman.jpg'); $this->assertEquals('bauffman.jpg', $this->txtPassword->getAttribute('rel')); - $this->txtPassword->setAttributes(array('id' => 'specialID')); - $this->assertEquals(array('id' => 'specialID', 'name' => 'name', 'class' => 'inputPassword', 'rel' => 'bauffman.jpg'), $this->txtPassword->getAttributes()); + $this->txtPassword->setAttributes(['id' => 'specialID']); + $this->assertEquals(['id' => 'specialID', 'name' => 'name', 'class' => 'inputPassword', 'rel' => 'bauffman.jpg'], $this->txtPassword->getAttributes()); } public function testIsFilled() @@ -54,7 +54,7 @@ public function testIsFilled() $this->assertFalse($this->txtPassword->isFilled()); $_POST['name'] = 'I am not empty'; $this->assertTrue($this->txtPassword->isFilled()); - $_POST['name'] = array('foo', 'bar'); + $_POST['name'] = ['foo', 'bar']; $this->assertTrue($this->txtPassword->isFilled()); } @@ -64,7 +64,7 @@ public function testIsAlphabetical() $this->assertFalse($this->txtPassword->isAlphabetical()); $_POST['name'] = 'Bauffman'; $this->assertTrue($this->txtPassword->isAlphabetical()); - $_POST['name'] = array('foo', 'bar'); + $_POST['name'] = ['foo', 'bar']; $this->assertTrue($this->txtPassword->isAlphabetical()); } @@ -74,7 +74,7 @@ public function testIsAlphaNumeric() $this->assertFalse($this->txtPassword->isAlphaNumeric()); $_POST['name'] = 'L33t'; $this->assertTrue($this->txtPassword->isAlphaNumeric()); - $_POST['name'] = array('foo', 'bar'); + $_POST['name'] = ['foo', 'bar']; $this->assertTrue($this->txtPassword->isAlphaNumeric()); } @@ -83,7 +83,7 @@ public function testIsMaximumCharacters() $_POST['name'] = 'Writing tests can be pretty frakkin boring'; $this->assertTrue($this->txtPassword->isMaximumCharacters(100)); $this->assertFalse($this->txtPassword->isMaximumCharacters(10)); - $_POST['name'] = array('foo', 'bar'); + $_POST['name'] = ['foo', 'bar']; $this->assertFalse($this->txtPassword->isMaximumCharacters(4)); } @@ -93,7 +93,7 @@ public function testIsMinimumCharacaters() $this->assertTrue($this->txtPassword->isMinimumCharacters(10)); $this->assertTrue($this->txtPassword->isMinimumCharacters(2)); $this->assertFalse($this->txtPassword->isMinimumCharacters(23)); - $_POST['name'] = array('foo', 'bar'); + $_POST['name'] = ['foo', 'bar']; $this->assertFalse($this->txtPassword->isMinimumCharacters(23)); } @@ -102,7 +102,7 @@ public function testIsValidAgainstRegexp() $_POST['name'] = 'Spoon'; $this->assertTrue($this->txtPassword->isValidAgainstRegexp('/([a-z]+)/')); $this->assertFalse($this->txtPassword->isValidAgainstRegexp('/([0-9]+)/')); - $_POST['name'] = array('foo', 'bar'); + $_POST['name'] = ['foo', 'bar']; $this->assertTrue($this->txtPassword->isValidAgainstRegexp('/Array/')); } @@ -111,7 +111,7 @@ public function testGetValue() $_POST['form'] = 'passwordfield'; $_POST['name'] = 'Bobby Tables, my friends call mééé'; $this->assertEquals($_POST['name'], $this->txtPassword->getValue()); - $_POST['name'] = array('foo', 'bar'); + $_POST['name'] = ['foo', 'bar']; $this->assertEquals('Array', $this->txtPassword->getValue()); } diff --git a/spoon/tests/form/SpoonFormRadiobuttonTest.php b/spoon/tests/form/SpoonFormRadiobuttonTest.php index e0ac11e..793bf0a 100644 --- a/spoon/tests/form/SpoonFormRadiobuttonTest.php +++ b/spoon/tests/form/SpoonFormRadiobuttonTest.php @@ -2,7 +2,7 @@ use PHPUnit\Framework\TestCase; -$includePath = dirname(dirname(dirname(dirname(__FILE__)))); +$includePath = dirname(__FILE__, 4); set_include_path(get_include_path() . PATH_SEPARATOR . $includePath); require_once 'spoon/spoon.php'; @@ -27,15 +27,15 @@ class SpoonFormRadiobuttonTest extends TestCase public function setup(): void { $this->frm = new SpoonForm('radiobutton'); - $gender[] = array('label' => 'Female', 'value' => 'F'); - $gender[] = array('label' => 'Male', 'value' => 'M'); + $gender[] = ['label' => 'Female', 'value' => 'F']; + $gender[] = ['label' => 'Male', 'value' => 'M']; $this->rbtGender = new SpoonFormRadiobutton('gender', $gender, 'M'); $this->frm->add($this->rbtGender); - $numeric = array( - array('value' => 1, 'label' => 'One'), - array('value' => 1.5, 'label' => 'One And A Half'), - ); + $numeric = [ + ['value' => 1, 'label' => 'One'], + ['value' => 1.5, 'label' => 'One And A Half'], + ]; $this->rbtNumeric = new SpoonFormRadiobutton('numeric', $numeric, '1'); } @@ -50,7 +50,7 @@ public function testGetValue() $this->assertEquals('M', $this->rbtGender->getValue()); $_POST['gender'] = 'F'; $this->assertEquals('F', $this->rbtGender->getValue()); - $_POST['gender'] = array('foo', 'bar'); + $_POST['gender'] = ['foo', 'bar']; $this->assertEquals('F', $this->rbtGender->getValue()); } @@ -61,7 +61,7 @@ public function testIsFilled() $this->assertTrue($this->rbtGender->isFilled()); $_POST['gender'] = 'foobar'; $this->assertFalse($this->rbtGender->isFilled()); - $_POST['gender'] = array('foo', 'bar'); + $_POST['gender'] = ['foo', 'bar']; $this->assertFalse($this->rbtGender->isFilled()); } @@ -94,21 +94,21 @@ protected function getExpectedNumericArray($checked) $oneChecked = ($checked === '1') ? ' checked="checked"' : ''; $oneHalfChecked = ($checked === '1.5') ? ' checked="checked"' : ''; - return array( - array( + return [ + [ 'rbtNumeric' => '', 'id' => 'numeric1', 'label' => 'One', 'value' => '1', 'element' => '', - ), - array( + ], + [ 'rbtNumeric' => '', 'id' => 'numeric1.5', 'label' => 'One And A Half', 'value' => '1.5', 'element' => '', - ) - ); + ] + ]; } } diff --git a/spoon/tests/form/SpoonFormTest.php b/spoon/tests/form/SpoonFormTest.php index a8926a9..720f184 100644 --- a/spoon/tests/form/SpoonFormTest.php +++ b/spoon/tests/form/SpoonFormTest.php @@ -4,7 +4,7 @@ date_default_timezone_set('Europe/Brussels'); -$includePath = dirname(dirname(dirname(dirname(__FILE__)))); +$includePath = dirname(__FILE__, 4); set_include_path(get_include_path() . PATH_SEPARATOR . $includePath); require_once 'spoon/spoon.php'; @@ -20,7 +20,7 @@ public function testMain() self::assertInstanceOf(SpoonFormCheckbox::class, $frm->getField('agree')); $frm->addDate('date', time(), 'd/m/Y'); self::assertInstanceOf(SpoonFormDate::class, $frm->getField('date')); - $frm->addDropdown('author', array(1 => 'Davy', 'Tijs', 'Dave'), 1); + $frm->addDropdown('author', [1 => 'Davy', 'Tijs', 'Dave'], 1); self::assertInstanceOf(SpoonFormDropdown::class, $frm->getField('author')); $frm->addFile('pdf'); self::assertInstanceOf(SpoonFormFile::class, $frm->getField('pdf')); @@ -28,11 +28,11 @@ public function testMain() self::assertInstanceOf(SpoonFormImage::class, $frm->getField('image')); $frm->addHidden('cant_see_me', 'whoop-tie-doo'); self::assertInstanceOf(SpoonFormHidden::class, $frm->getField('cant_see_me')); - $frm->addMultiCheckbox('hobbies', array(array('label' => 'Swimming', 'value' => 'swimming'))); + $frm->addMultiCheckbox('hobbies', [['label' => 'Swimming', 'value' => 'swimming']]); self::assertInstanceOf(SpoonFormMultiCheckbox::class, $frm->getField('hobbies')); $frm->addPassword('top_sekret', 'stars-and-stripes'); self::assertInstanceOf(SpoonFormPassword::class, $frm->getField('top_sekret')); - $frm->addRadiobutton('gender', array(array('label' => 'Male', 'value' => 'male'))); + $frm->addRadiobutton('gender', [['label' => 'Male', 'value' => 'male']]); self::assertInstanceOf(SpoonFormRadiobutton::class, $frm->getField('gender')); $frm->addTextarea('message', 'big piece of text'); self::assertInstanceOf(SpoonFormTextarea::class, $frm->getField('message')); diff --git a/spoon/tests/form/SpoonFormTextTest.php b/spoon/tests/form/SpoonFormTextTest.php index 978bc69..eb0bde1 100644 --- a/spoon/tests/form/SpoonFormTextTest.php +++ b/spoon/tests/form/SpoonFormTextTest.php @@ -2,7 +2,7 @@ use PHPUnit\Framework\TestCase; -$includePath = dirname(dirname(dirname(dirname(__FILE__)))); +$includePath = dirname(__FILE__, 4); set_include_path(get_include_path() . PATH_SEPARATOR . $includePath); require_once 'spoon/spoon.php'; @@ -45,8 +45,8 @@ public function testAttributes() { $this->txtName->setAttribute('rel', 'bauffman.jpg'); $this->assertEquals('bauffman.jpg', $this->txtName->getAttribute('rel')); - $this->txtName->setAttributes(array('id' => 'specialID')); - $this->assertEquals(array('id' => 'specialID', 'name' => 'name', 'type' => 'text', 'class' => 'inputText', 'rel' => 'bauffman.jpg'), $this->txtName->getAttributes()); + $this->txtName->setAttributes(['id' => 'specialID']); + $this->assertEquals(['id' => 'specialID', 'name' => 'name', 'type' => 'text', 'class' => 'inputText', 'rel' => 'bauffman.jpg'], $this->txtName->getAttributes()); } public function testIsFilled() @@ -55,7 +55,7 @@ public function testIsFilled() $this->assertFalse($this->txtName->isFilled()); $_POST['name'] = 'I am not empty'; $this->assertTrue($this->txtName->isFilled()); - $_POST['name'] = array('foo', 'bar'); + $_POST['name'] = ['foo', 'bar']; $this->assertTrue($this->txtName->isFilled()); } @@ -67,7 +67,7 @@ public function testIsAlphabetical() $this->assertTrue($this->txtName->isAlphabetical()); // since the array will be casted to a string, this will be 'Array' and that is alphabetical :) - $_POST['name'] = array('foo', 'bar'); + $_POST['name'] = ['foo', 'bar']; $this->assertTrue($this->txtName->isAlphabetical()); } @@ -79,7 +79,7 @@ public function testIsAphaNumeric() $this->assertTrue($this->txtName->isAlphaNumeric()); // since the array will be casted to a string, this will be 'Array' and that is alphabetical :) - $_POST['name'] = array('foo', 'bar'); + $_POST['name'] = ['foo', 'bar']; $this->assertTrue($this->txtName->isAlphaNumeric()); } @@ -91,7 +91,7 @@ public function testIsBetween() $this->assertFalse($this->txtName->isBetween(200, 201)); $this->assertFalse($this->txtName->isBetween(1000, 200)); - $_POST['name'] = array('foo', 'bar'); + $_POST['name'] = ['foo', 'bar']; $this->assertFalse($this->txtName->isBetween(10, 200)); } @@ -111,7 +111,7 @@ public function testIsBool() $this->assertFalse($this->txtName->isBool()); $_POST['name'] = '090'; $this->assertFalse($this->txtName->isBool()); - $_POST['name'] = array('foo', 'bar'); + $_POST['name'] = ['foo', 'bar']; $this->assertFalse($this->txtName->isBool()); } @@ -123,7 +123,7 @@ public function testIsDigital() $this->assertFalse($this->txtName->isDigital()); $_POST['name'] = ''; $this->assertFalse($this->txtName->isDigital()); - $_POST['name'] = array('foo', 'bar'); + $_POST['name'] = ['foo', 'bar']; $this->assertFalse($this->txtName->isDigital()); } @@ -134,7 +134,7 @@ public function testIsEmail() $this->assertTrue($this->txtName->isEmail()); $_POST['name'] = ''; $this->assertFalse($this->txtName->isEmail()); - $_POST['name'] = array('foo', 'bar'); + $_POST['name'] = ['foo', 'bar']; $this->assertFalse($this->txtName->isEmail()); } @@ -146,7 +146,7 @@ public function testIsFilename() $this->assertTrue($this->txtName->isFilename()); // since the array will be casted to a string, this will be 'Array' and that is a possible filename :) - $_POST['name'] = array('foo', 'bar'); + $_POST['name'] = ['foo', 'bar']; $this->assertTrue($this->txtName->isFilename()); } @@ -164,7 +164,7 @@ public function testIsFloat() $_POST['name'] = '-1,35'; $this->assertTrue($this->txtName->isFloat(null, true)); - $_POST['name'] = array('foo', 'bar', 190); + $_POST['name'] = ['foo', 'bar', 190]; $this->assertFalse($this->txtName->isFloat()); } @@ -175,7 +175,7 @@ public function testIsGreatherThan() $this->assertTrue($this->txtName->isGreaterThan(-199)); $this->assertFalse($this->txtName->isGreaterThan(199)); - $_POST['name'] = array('foo', 'bar'); + $_POST['name'] = ['foo', 'bar']; $this->assertFalse($this->txtName->isGreaterThan(1337)); } @@ -189,7 +189,7 @@ public function testIsInteger() $this->assertFalse($this->txtName->isInteger()); $_POST['name'] = '1,9'; $this->assertFalse($this->txtName->isInteger()); - $_POST['name'] = array('foo', 'bar'); + $_POST['name'] = ['foo', 'bar']; $this->assertFalse($this->txtName->isInteger()); } @@ -200,7 +200,7 @@ public function testIsIp() $this->assertTrue($this->txtName->isIp()); $_POST['name'] = '192.168.1.101'; $this->assertTrue($this->txtName->isIp()); - $_POST['name'] = array('foo', 'bar'); + $_POST['name'] = ['foo', 'bar']; $this->assertFalse($this->txtName->isIp()); } @@ -211,7 +211,7 @@ public function testIsMaximum() $_POST['name'] = 199; $this->assertFalse($this->txtName->isMaximum(18)); $this->assertTrue($this->txtName->isMaximum(300)); - $_POST['name'] = array('foo', 'bar'); + $_POST['name'] = ['foo', 'bar']; $this->assertTrue($this->txtName->isMaximum(200)); } @@ -220,7 +220,7 @@ public function testIsMaximumCharacters() $_POST['name'] = 'Writing tests can be pretty frakkin boring'; $this->assertTrue($this->txtName->isMaximumCharacters(100)); $this->assertFalse($this->txtName->isMaximumCharacters(10)); - $_POST['name'] = array('foo', 'bar'); + $_POST['name'] = ['foo', 'bar']; $this->assertTrue($this->txtName->isMaximumCharacters(10)); } @@ -230,7 +230,7 @@ public function testIsMinimum() $this->assertTrue($this->txtName->isMinimum(5)); $this->assertTrue($this->txtName->isMinimum(4)); $this->assertFalse($this->txtName->isMinimum(7)); - $_POST['name'] = array('foo', 'bar'); + $_POST['name'] = ['foo', 'bar']; $this->assertFalse($this->txtName->isMinimum(7)); } @@ -240,7 +240,7 @@ public function testIsMinimumCharacters() $this->assertTrue($this->txtName->isMinimumCharacters(10)); $this->assertTrue($this->txtName->isMinimumCharacters(2)); $this->assertFalse($this->txtName->isMinimumCharacters(23)); - $_POST['name'] = array('foo', 'bar'); + $_POST['name'] = ['foo', 'bar']; $this->assertFalse($this->txtName->isMinimumCharacters(23)); } @@ -252,7 +252,7 @@ public function testIsNumeric() $this->assertTrue($this->txtName->isNumeric()); $_POST['name'] = 'I can haz two cheezeburgers?'; $this->assertFalse($this->txtName->isNumeric()); - $_POST['name'] = array('foo', 'bar'); + $_POST['name'] = ['foo', 'bar']; $this->assertFalse($this->txtName->isNumeric()); } @@ -263,7 +263,7 @@ public function testIsSmallerThan() $this->assertTrue($this->txtName->isSmallerThan(200)); $this->assertFalse($this->txtName->isSmallerThan(0)); $this->assertFalse($this->txtName->isSmallerThan(-16)); - $_POST['name'] = array('foo', 'bar'); + $_POST['name'] = ['foo', 'bar']; $this->assertFalse($this->txtName->isSmallerThan(0)); } @@ -275,7 +275,7 @@ public function testIsURL() $this->assertTrue($this->txtName->isURL()); $_POST['name'] = 'www.spoon-library.com'; $this->assertTrue($this->txtName->isURL()); - $_POST['name'] = array('foo', 'bar'); + $_POST['name'] = ['foo', 'bar']; $this->assertFalse($this->txtName->isURL()); } @@ -284,7 +284,7 @@ public function testIsValidAgainstRegexp() $_POST['name'] = 'Spoon'; $this->assertTrue($this->txtName->isValidAgainstRegexp('/([a-z]+)/')); $this->assertFalse($this->txtName->isValidAgainstRegexp('/([0-9]+)/')); - $_POST['name'] = array('foo', 'bar'); + $_POST['name'] = ['foo', 'bar']; $this->assertTrue($this->txtName->isValidAgainstRegexp('/Array/')); } @@ -294,7 +294,7 @@ public function testGetValue() $_POST['name'] = 'Bobby Tables, my friends call mééé'; $this->assertEquals(SpoonFilter::htmlspecialchars($_POST['name']), $this->txtName->getValue()); $this->assertEquals($_POST['name'], $this->txtName->getValue(true)); - $_POST['name'] = array('foo', 'bar'); + $_POST['name'] = ['foo', 'bar']; $this->assertEquals('Array', $this->txtName->getValue()); } diff --git a/spoon/tests/form/SpoonFormTextareaTest.php b/spoon/tests/form/SpoonFormTextareaTest.php index f441608..3aea147 100644 --- a/spoon/tests/form/SpoonFormTextareaTest.php +++ b/spoon/tests/form/SpoonFormTextareaTest.php @@ -2,7 +2,7 @@ use PHPUnit\Framework\TestCase; -$includePath = dirname(dirname(dirname(dirname(__FILE__)))); +$includePath = dirname(__FILE__, 4); set_include_path(get_include_path() . PATH_SEPARATOR . $includePath); require_once 'spoon/spoon.php'; @@ -45,8 +45,8 @@ public function testAttributes() { $this->txtMessage->setAttribute('rel', 'bauffman.jpg'); $this->assertEquals('bauffman.jpg', $this->txtMessage->getAttribute('rel')); - $this->txtMessage->setAttributes(array('id' => 'specialID')); - $this->assertEquals(array('id' => 'specialID', 'name' => 'message', 'cols' => 62, 'rows' => 5, 'class' => 'inputTextarea', 'rel' => 'bauffman.jpg'), $this->txtMessage->getAttributes()); + $this->txtMessage->setAttributes(['id' => 'specialID']); + $this->assertEquals(['id' => 'specialID', 'name' => 'message', 'cols' => 62, 'rows' => 5, 'class' => 'inputTextarea', 'rel' => 'bauffman.jpg'], $this->txtMessage->getAttributes()); } public function testIsFilled() @@ -54,7 +54,7 @@ public function testIsFilled() $this->assertFalse($this->txtMessage->isFilled()); $_POST['message'] = 'I am not empty'; $this->assertTrue($this->txtMessage->isFilled()); - $_POST['message'] = array('foo', 'bar'); + $_POST['message'] = ['foo', 'bar']; $this->assertTrue($this->txtMessage->isFilled()); } @@ -64,7 +64,7 @@ public function testIsAlphabetical() $this->assertFalse($this->txtMessage->isAlphabetical()); $_POST['message'] = 'Bauffman'; $this->assertTrue($this->txtMessage->isAlphabetical()); - $_POST['message'] = array('foo', 'bar'); + $_POST['message'] = ['foo', 'bar']; $this->assertTrue($this->txtMessage->isAlphabetical()); } @@ -74,7 +74,7 @@ public function testIsAlphaNumeric() $this->assertFalse($this->txtMessage->isAlphaNumeric()); $_POST['message'] = 'L33t'; $this->assertTrue($this->txtMessage->isAlphaNumeric()); - $_POST['message'] = array('foo', 'bar'); + $_POST['message'] = ['foo', 'bar']; $this->assertTrue($this->txtMessage->isAlphaNumeric()); } @@ -83,7 +83,7 @@ public function testIsMaximumCharacters() $_POST['message'] = 'Writing tests can be pretty frakkin boring'; $this->assertTrue($this->txtMessage->isMaximumCharacters(100)); $this->assertFalse($this->txtMessage->isMaximumCharacters(10)); - $_POST['message'] = array('foo', 'bar'); + $_POST['message'] = ['foo', 'bar']; $this->assertFalse($this->txtMessage->isMaximumCharacters(0)); } @@ -93,7 +93,7 @@ public function testIsMinimumCharacters() $this->assertTrue($this->txtMessage->isMinimumCharacters(10)); $this->assertTrue($this->txtMessage->isMinimumCharacters(2)); $this->assertFalse($this->txtMessage->isMinimumCharacters(23)); - $_POST['message'] = array('foo', 'bar'); + $_POST['message'] = ['foo', 'bar']; $this->assertFalse($this->txtMessage->isMinimumCharacters(10)); } @@ -103,7 +103,7 @@ public function testGetValue() $_POST['message'] = 'Bobby Tables, my friends call mééé'; $this->assertEquals(SpoonFilter::htmlspecialchars($_POST['message']), $this->txtMessage->getValue()); $this->assertEquals($_POST['message'], $this->txtMessage->getValue(true)); - $_POST['message'] = array('foo', 'bar'); + $_POST['message'] = ['foo', 'bar']; $this->assertEquals('Array', $this->txtMessage->getValue(true)); } diff --git a/spoon/tests/form/SpoonFormTimeTest.php b/spoon/tests/form/SpoonFormTimeTest.php index f04a676..cea52d6 100644 --- a/spoon/tests/form/SpoonFormTimeTest.php +++ b/spoon/tests/form/SpoonFormTimeTest.php @@ -4,7 +4,7 @@ date_default_timezone_set('Europe/Brussels'); -$includePath = dirname(dirname(dirname(dirname(__FILE__)))); +$includePath = dirname(__FILE__, 4); set_include_path(get_include_path() . PATH_SEPARATOR . $includePath); require_once 'spoon/spoon.php'; @@ -47,8 +47,8 @@ public function testAttributes() { $this->txtTime->setAttribute('rel', 'bauffman.jpg'); $this->assertEquals('bauffman.jpg', $this->txtTime->getAttribute('rel')); - $this->txtTime->setAttributes(array('id' => 'specialID')); - $this->assertEquals(array('id' => 'specialID', 'name' => 'time','maxlength' => 5, 'class' => 'inputTimefield', 'rel' => 'bauffman.jpg'), $this->txtTime->getAttributes()); + $this->txtTime->setAttributes(['id' => 'specialID']); + $this->assertEquals(['id' => 'specialID', 'name' => 'time','maxlength' => 5, 'class' => 'inputTimefield', 'rel' => 'bauffman.jpg'], $this->txtTime->getAttributes()); } public function testIsFilled() @@ -56,7 +56,7 @@ public function testIsFilled() $this->assertFalse($this->txtTime->isFilled()); $_POST['time'] = '14:55'; $this->assertTrue($this->txtTime->isFilled()); - $_POST['name'] = array('foo', 'bar'); + $_POST['name'] = ['foo', 'bar']; $this->assertTrue($this->txtTime->isFilled()); } @@ -74,7 +74,7 @@ public function testIsValid() $this->assertFalse($this->txtTime->isValid()); $_POST['time'] = '1k:2b'; $this->assertFalse($this->txtTime->isValid()); - $_POST['name'] = array('foo', 'bar'); + $_POST['name'] = ['foo', 'bar']; $this->assertFalse($this->txtTime->isValid()); } @@ -89,7 +89,7 @@ public function testGetValue() $_POST['form'] = 'timefield'; $_POST['time'] = '14:55'; $this->assertEquals('14:55', $this->txtTime->getValue()); - $_POST['time'] = array('foo', 'bar'); + $_POST['time'] = ['foo', 'bar']; $this->assertEquals('Array', $this->txtTime->getValue()); } diff --git a/spoon/tests/locale/SpoonLocaleTest.php b/spoon/tests/locale/SpoonLocaleTest.php index 0ce0041..8e6d36a 100644 --- a/spoon/tests/locale/SpoonLocaleTest.php +++ b/spoon/tests/locale/SpoonLocaleTest.php @@ -2,7 +2,7 @@ use PHPUnit\Framework\TestCase; -$includePath = dirname(dirname(dirname(dirname(__FILE__)))); +$includePath = dirname(__FILE__, 4); set_include_path(get_include_path() . PATH_SEPARATOR . $includePath); require_once 'spoon/spoon.php'; @@ -11,7 +11,7 @@ class SpoonLocaleTest extends TestCase { public function testGetAvailableLanguages() { - $this->assertEquals(array('de', 'en', 'es', 'fr', 'nl', 'it'), SpoonLocale::getAvailableLanguages()); + $this->assertEquals(['de', 'en', 'es', 'fr', 'nl', 'it'], SpoonLocale::getAvailableLanguages()); } public function testGetConjunction() diff --git a/spoon/tests/template/Collection.php b/spoon/tests/template/Collection.php index e3d36f9..5c2ea03 100644 --- a/spoon/tests/template/Collection.php +++ b/spoon/tests/template/Collection.php @@ -5,34 +5,31 @@ */ class Collection implements Countable, IteratorAggregate, ArrayAccess { - private $array = array(); - - public function count() + public function count(): int { return count($this->array); } - public function __construct(array $array) - { - $this->array = $array; - } + public function __construct(private array $array) + { + } - public function getIterator() + public function getIterator(): Traversable { return new ArrayIterator($this->array); } - public function offsetExists($offset) + public function offsetExists(mixed $offset): bool { - isset($this->array[$offset]); + return isset($this->array[$offset]); } - public function offsetGet($offset) + public function offsetGet(mixed $offset): mixed { - return isset($this->array[$offset]) ? $this->array[$offset] : null; + return $this->array[$offset] ?? null; } - public function offsetSet($offset, $value) + public function offsetSet(mixed $offset, mixed $value): void { if(is_null($offset)) { @@ -44,8 +41,8 @@ public function offsetSet($offset, $value) } } - public function offsetUnset($offset) + public function offsetUnset(mixed $offset): void { - unset($this->container[$offset]); + unset($this->array[$offset]); } } diff --git a/spoon/tests/template/SpoonCompilerTest.php b/spoon/tests/template/SpoonCompilerTest.php index fe5cac4..7680d59 100644 --- a/spoon/tests/template/SpoonCompilerTest.php +++ b/spoon/tests/template/SpoonCompilerTest.php @@ -2,7 +2,7 @@ use PHPUnit\Framework\TestCase; -$includePath = dirname(dirname(dirname(dirname(__FILE__)))); +$includePath = dirname(__FILE__, 4); set_include_path(get_include_path() . PATH_SEPARATOR . $includePath); require_once 'spoon/spoon.php'; @@ -18,7 +18,7 @@ public function setUp(): void // create a spoon template $this->tpl = new SpoonTemplate(); $this->tpl->setForceCompile(true); - $this->tpl->setCompileDirectory(dirname(__FILE__) . '/cache'); + $this->tpl->setCompileDirectory(__DIR__ . '/cache'); } function testParseVariables() @@ -31,7 +31,7 @@ function testParseArrays() { $this->tpl->assign( 'array', - array('name' => 'Array name') + ['name' => 'Array name'] ); $this->runTests('Array name', 'array.tpl'); } @@ -49,11 +49,11 @@ function testParseNestedArrays() { $this->tpl->assign( 'array', - array( - 'inner_array' => array( + [ + 'inner_array' => [ 'name' => 'Array name' - ) - ) + ] + ] ); $this->runTests('Array name', 'nested_array.tpl'); } @@ -72,7 +72,7 @@ function testParseNestedObjects() function testParseArrayInObject() { - $nestedArray = array('name' => 'Inside an object'); + $nestedArray = ['name' => 'Inside an object']; $object = new TestObject(); $object->setArray($nestedArray); @@ -85,10 +85,10 @@ function testIterationOverArray() { $this->tpl->assign( 'array', - array( - array('name' => 'Foo'), - array('name' => 'Bar'), - ) + [ + ['name' => 'Foo'], + ['name' => 'Bar'], + ] ); $this->runTests('FooBar', 'iteration_over_array.tpl'); } @@ -97,12 +97,12 @@ function testIterationOverNestedArray() { $this->tpl->assign( 'array', - array( - 'nested_array' => array( - array('name' => 'Foo'), - array('name' => 'Bar'), - ) - ) + [ + 'nested_array' => [ + ['name' => 'Foo'], + ['name' => 'Bar'], + ] + ] ); $this->runTests('FooBar', 'iteration_over_nested_array.tpl'); } @@ -111,10 +111,10 @@ function testIterationOverArrayInObject() { $object = new TestObject(); $object->setArray( - array( - array('name' => 'Foo'), - array('name' => 'Bar'), - ) + [ + ['name' => 'Foo'], + ['name' => 'Bar'], + ] ); $this->tpl->assign('object', $object); @@ -129,17 +129,17 @@ function testIterationOverArrayOfObjects() $object2 = new TestObject(); $object2->setName('Bar'); - $this->tpl->assign('array', array($object1, $object2)); + $this->tpl->assign('array', [$object1, $object2]); $this->runTests('FooBar', 'iteration_over_array_of_objects.tpl'); } function testIterationOverCollection() { $collection = new Collection( - array( - array('name' => 'Foo'), - array('name' => 'Bar'), - ) + [ + ['name' => 'Foo'], + ['name' => 'Bar'], + ] ); $this->tpl->assign('collection', $collection); @@ -155,7 +155,7 @@ function testIterationOverCollectionOfObjects() $object2->setName('Object2'); $collection = new Collection( - array($object1, $object2) + [$object1, $object2] ); $this->tpl->assign('collection', $collection); @@ -166,22 +166,22 @@ function testCycle() { $this->tpl->assign( 'array', - array( - array('number' => 'One'), - array('number' => 'Two'), - array('number' => 'Three'), - ) + [ + ['number' => 'One'], + ['number' => 'Two'], + ['number' => 'Three'], + ] ); $this->runTests('One: Odd, Two: Even, Three: Odd, ', 'cycle.tpl'); } function testCycleOverArrayInObject() { - $array = array( - array('number' => '1'), - array('number' => '2'), - array('number' => '3'), - ); + $array = [ + ['number' => '1'], + ['number' => '2'], + ['number' => '3'], + ]; $object = new TestObject(); $object->setArray($array); $this->tpl->assign('object', $array); @@ -190,11 +190,11 @@ function testCycleOverArrayInObject() function testCycleOverCollection() { - $array = array( - array('number' => '0'), - array('number' => '1'), - array('number' => '2'), - ); + $array = [ + ['number' => '0'], + ['number' => '1'], + ['number' => '2'], + ]; $collection = new Collection($array); $this->tpl->assign('collection', $collection); $this->runTests('0: Even, 1: Odd, 2: Even, ', 'cycle_over_collection.tpl'); @@ -204,22 +204,22 @@ function testFirstAndLast() { $this->tpl->assign( 'array', - array( - array('number' => 'One'), - array('number' => 'Two'), - array('number' => 'Three'), - ) + [ + ['number' => 'One'], + ['number' => 'Two'], + ['number' => 'Three'], + ] ); $this->runTests('First: One, Last: Three', 'first_last.tpl'); } function testFirstAndLastForArrayInObject() { - $array = array( - array('number' => '1'), - array('number' => '2'), - array('number' => '3'), - ); + $array = [ + ['number' => '1'], + ['number' => '2'], + ['number' => '3'], + ]; $object = new TestObject(); $object->setArray($array); $this->tpl->assign('object', $array); @@ -228,11 +228,11 @@ function testFirstAndLastForArrayInObject() function testFirstAndLastForCollection() { - $array = array( - array('number' => '0'), - array('number' => '1'), - array('number' => '2'), - ); + $array = [ + ['number' => '0'], + ['number' => '1'], + ['number' => '2'], + ]; $collection = new Collection($array); $this->tpl->assign('object', $collection); $this->runTests('First: 0, Last: 2', 'first_last_array_in_object.tpl'); @@ -253,7 +253,7 @@ function testOption() $this->runTests('Yes', 'option.tpl'); // array with content - $this->tpl->assign('test', array('tralala')); + $this->tpl->assign('test', ['tralala']); $this->runTests('Yes', 'option.tpl'); // object @@ -273,16 +273,16 @@ function testOption() $this->runTests('No', 'option.tpl'); // empty array - $this->tpl->assign('test', array()); + $this->tpl->assign('test', []); $this->runTests('No', 'option.tpl'); } function testOptionInArray() { - $this->tpl->assign('array', array('boolean' => true)); + $this->tpl->assign('array', ['boolean' => true]); $this->runTests('Yes', 'option_in_array.tpl'); - $this->tpl->assign('array', array('boolean' => false)); + $this->tpl->assign('array', ['boolean' => false]); $this->runTests('No', 'option_in_array.tpl'); } @@ -310,16 +310,16 @@ function testOptionInObject() function testOptionInIteration() { // in an array - $array = array( - array( + $array = [ + [ 'boolean' => true, 'name' => 'True', - ), - array( + ], + [ 'boolean' => false, 'name' => 'False', - ), - ); + ], + ]; $this->tpl->assign('items', $array); $this->runTests('True', 'option_in_iteration.tpl'); @@ -330,7 +330,7 @@ function testOptionInIteration() $object2 = new TestObject(); $object2->setBoolean(false); $object2->setName('False'); - $array = array($object1, $object2); + $array = [$object1, $object2]; $this->tpl->assign('items', $array); $this->runTests('True', 'option_in_iteration.tpl'); @@ -339,16 +339,16 @@ function testOptionInIteration() function testOptionNotInIteration() { // in an array - $array = array( - array( + $array = [ + [ 'boolean' => true, 'name' => 'True', - ), - array( + ], + [ 'boolean' => false, 'name' => 'False', - ), - ); + ], + ]; $this->tpl->assign('items', $array); $this->runTests('False', 'option_not_in_iteration.tpl'); @@ -359,7 +359,7 @@ function testOptionNotInIteration() $object2 = new TestObject(); $object2->setBoolean(false); $object2->setName('False'); - $array = array($object1, $object2); + $array = [$object1, $object2]; $this->tpl->assign('items', $array); $this->runTests('False', 'option_not_in_iteration.tpl'); @@ -398,7 +398,7 @@ function testTemplateModifierObject() function testTemplateModifierWithVariables() { $this->tpl->assign('string', '%1$s %2$s'); - $this->tpl->assign('array', array('foo' => 'foo', 'bar' => 'bar')); + $this->tpl->assign('array', ['foo' => 'foo', 'bar' => 'bar']); $this->runTests('foo bar', 'template_modifier_with_vars.tpl'); } @@ -410,7 +410,7 @@ function testTemplateModifierInIterationOverArrayOfObjects() $object2 = new TestObject(); $object2->setName('bar'); - $this->tpl->assign('array', array($object1, $object2)); + $this->tpl->assign('array', [$object1, $object2]); $this->runTests('FooBar', 'template_modifier_iteration_over_array_of_objects.tpl'); } @@ -435,6 +435,6 @@ protected function runTests($output, $template) protected function getTemplatePath($templateName) { - return dirname(__FILE__) . '/templates/' . $templateName; + return __DIR__ . '/templates/' . $templateName; } } diff --git a/spoon/tests/template/SpoonModifiersTest.php b/spoon/tests/template/SpoonModifiersTest.php index a5e260f..4552118 100644 --- a/spoon/tests/template/SpoonModifiersTest.php +++ b/spoon/tests/template/SpoonModifiersTest.php @@ -4,7 +4,7 @@ date_default_timezone_set('Europe/Brussels'); -$includePath = dirname(dirname(dirname(dirname(__FILE__)))); +$includePath = dirname(__FILE__, 4); set_include_path(get_include_path() . PATH_SEPARATOR . $includePath); require_once 'spoon/spoon.php'; @@ -14,12 +14,12 @@ class SpoonTemplateModifiersTest extends TestCase public function testClearModifiers() { SpoonTemplateModifiers::clearModifiers(); - $this->assertEquals(array(), SpoonTemplateModifiers::getModifiers()); + $this->assertEquals([], SpoonTemplateModifiers::getModifiers()); } public function testCreateHTMLLinks() { - $tlds = array( + $tlds = [ 'aero', 'asia', 'biz', 'cat', 'com', 'coop', 'edu', 'gov', 'info', 'int', 'jobs', 'mil', 'mobi', 'museum', 'name', 'net', 'org', 'pro', 'tel', 'travel', 'ac', 'ad', 'ae', 'af', 'ag', 'ai', 'al', 'am', 'an', 'ao', 'aq', 'ar', 'as', 'at', 'au', 'aw', 'ax', 'az', 'ba', 'bb', 'bd' ,'be', 'bf', 'bg', @@ -36,7 +36,7 @@ public function testCreateHTMLLinks() 'sn', 'so', 'sr', 'st', 'su', 'sv', 'sy', 'sz', 'tc', 'td', 'tf', 'tg', 'th', 'tj', 'tk', 'tl', 'tm', 'tn', 'to', 'tp', 'tr', 'tt', 'tv', 'tw', 'tz', 'ua', 'ug', 'uk', 'us', 'uy', 'uz', 'va', 'vc', 've', 'vg', 'vi', 'vn', 'vu', 'wf', 'ws', 'ye', 'yt', 'yu', 'za', 'zm', 'zw', 'arpa' - ); + ]; foreach($tlds as $tld) { diff --git a/spoon/tests/template/SpoonTemplateTest.php b/spoon/tests/template/SpoonTemplateTest.php index f7fb9b7..0a105f0 100644 --- a/spoon/tests/template/SpoonTemplateTest.php +++ b/spoon/tests/template/SpoonTemplateTest.php @@ -19,9 +19,9 @@ public function testGetAssignedValue(): void { $tpl = new SpoonTemplate(); $tpl->assign('name', 'value'); - $tpl->assign('list', array('name' => 'Erik Bauffman')); + $tpl->assign('list', ['name' => 'Erik Bauffman']); $this->assertEquals('value', $tpl->getAssignedValue('name')); - $this->assertEquals(array('name' => 'Erik Bauffman'), $tpl->getAssignedValue('list')); + $this->assertEquals(['name' => 'Erik Bauffman'], $tpl->getAssignedValue('list')); $this->assertEquals(null, $tpl->getAssignedValue('wtf-this-is-super-cool')); } } diff --git a/spoon/tests/thumbnail/SpoonThumbnailTest.php b/spoon/tests/thumbnail/SpoonThumbnailTest.php index ec2bcb0..ac8b5ff 100644 --- a/spoon/tests/thumbnail/SpoonThumbnailTest.php +++ b/spoon/tests/thumbnail/SpoonThumbnailTest.php @@ -2,7 +2,7 @@ use PHPUnit\Framework\TestCase; -$includePath = dirname(dirname(dirname(dirname(__FILE__)))); +$includePath = dirname(__FILE__, 4); set_include_path(get_include_path() . PATH_SEPARATOR . $includePath); require_once 'spoon/spoon.php'; @@ -12,7 +12,7 @@ class SpoonThumbnailTest extends TestCase public function testIsSupportedFileType() { $this->assertTrue( - SpoonThumbnail::isSupportedFileType(dirname(dirname(realpath(__FILE__))) . '/tmp/spoon.jpg') + SpoonThumbnail::isSupportedFileType(dirname(realpath(__FILE__), 2) . '/tmp/spoon.jpg') ); } } diff --git a/spoon/thumbnail/thumbnail.php b/spoon/thumbnail/thumbnail.php index 7bb58e6..7a8e3d4 100644 --- a/spoon/thumbnail/thumbnail.php +++ b/spoon/thumbnail/thumbnail.php @@ -140,26 +140,13 @@ public function __construct($filename, $width = null, $height = null, $strict = public static function isSupportedFileType($filename) { // get watermarkfile properties - list($width, $height, $type) = @getimagesize($filename); + [$width, $height, $type] = @getimagesize($filename); // create image from sourcefile - switch($type) - { - // gif - case IMG_GIF: - - // jpg - case IMG_JPG: - - // png - case 3: - case IMG_PNG: - return true; - break; - - default: - return false; - } + return match ($type) { + IMG_GIF, IMG_JPG, 3, IMG_PNG => true, + default => false, + }; } @@ -236,7 +223,7 @@ public function parseToFile($filename, $quality = 100, $chmod = 0666) } // invalid extension - if(SpoonFilter::getValue($extension, array('gif', 'jpeg', 'jpg', 'png'), '') == '') + if(SpoonFilter::getValue($extension, ['gif', 'jpeg', 'jpg', 'png'], '') == '') { if($this->strict) throw new SpoonThumbnailException('Only gif, jpeg, jpg or png are allowed types.'); return false; @@ -260,7 +247,7 @@ public function parseToFile($filename, $quality = 100, $chmod = 0666) $currentMime = (string) $imageProperties['mime']; // file is the same? - if(($currentType == IMAGETYPE_GIF && $extension == 'gif') || ($currentType == IMAGETYPE_JPEG && in_array($extension, array('jpg', 'jpeg'))) || ($currentType == IMAGETYPE_PNG && $extension == 'png')) + if(($currentType == IMAGETYPE_GIF && $extension == 'gif') || ($currentType == IMAGETYPE_JPEG && in_array($extension, ['jpg', 'jpeg'])) || ($currentType == IMAGETYPE_PNG && $extension == 'png')) { if($currentWidth == $this->width && $currentHeight == $this->height) { @@ -425,24 +412,12 @@ private function resizeImageWithForceAspectRatio($currentWidth, $currentHeight, } // read current image - switch($currentType) - { - case IMG_GIF: - $currentImage = @imagecreatefromgif($this->filename); - break; - - case IMG_JPG: - $currentImage = @imagecreatefromjpeg($this->filename); - break; - - case 3: - case IMG_PNG: - $currentImage = @imagecreatefrompng($this->filename); - break; - - default: - throw new SpoonThumbnailException('The file you specified "' . $currentMime . '" is not supported. Only gif, jpeg, jpg and png are supported.'); - } + $currentImage = match ($currentType) { + IMG_GIF => @imagecreatefromgif($this->filename), + IMG_JPG => @imagecreatefromjpeg($this->filename), + 3, IMG_PNG => @imagecreatefrompng($this->filename), + default => throw new SpoonThumbnailException('The file you specified "' . $currentMime . '" is not supported. Only gif, jpeg, jpg and png are supported.'), + }; // validate image if($currentImage === false) throw new SpoonThumbnailException('The file you specified is corrupt.'); @@ -451,7 +426,7 @@ private function resizeImageWithForceAspectRatio($currentWidth, $currentHeight, @imagealphablending($currentImage, false); // transparency supported for current image - if(in_array($currentType, array(IMG_GIF, 3, IMG_PNG))) + if(in_array($currentType, [IMG_GIF, 3, IMG_PNG])) { // get transparent color $colorTransparent = @imagecolorallocatealpha($currentImage, 0, 0, 0, 127); @@ -474,7 +449,7 @@ private function resizeImageWithForceAspectRatio($currentWidth, $currentHeight, @imagealphablending($this->image, false); // transparency supported - if(in_array($currentType, array(IMG_GIF, 3, IMG_PNG))) + if(in_array($currentType, [IMG_GIF, 3, IMG_PNG])) { // get transparent color $colorTransparent = @imagecolorallocatealpha($this->image, 0, 0, 0, 127); @@ -548,24 +523,12 @@ private function resizeImageWithoutForceAspectRatio($currentWidth, $currentHeigh $newHeight = $this->height; // read current image - switch($currentType) - { - case IMG_GIF: - $currentImage = @imagecreatefromgif($this->filename); - break; - - case IMG_JPG: - $currentImage = @imagecreatefromjpeg($this->filename); - break; - - case 3: - case IMG_PNG: - $currentImage = @imagecreatefrompng($this->filename); - break; - - default: - throw new SpoonThumbnailException('The file you specified "' . $currentMime . '" is not supported. Only gif, jpeg, jpg and png are supported.'); - } + $currentImage = match ($currentType) { + IMG_GIF => @imagecreatefromgif($this->filename), + IMG_JPG => @imagecreatefromjpeg($this->filename), + 3, IMG_PNG => @imagecreatefrompng($this->filename), + default => throw new SpoonThumbnailException('The file you specified "' . $currentMime . '" is not supported. Only gif, jpeg, jpg and png are supported.'), + }; // current width is larger then current height if($currentWidth > $currentHeight) @@ -636,9 +599,6 @@ private function resizeImageWithoutForceAspectRatio($currentWidth, $currentHeigh // resize $success = @imagecopyresampled($tempImage, $currentImage, 0, 0, 0, 0, $tempWidth, $tempHeight, $currentWidth, $currentHeight); - // destroy original image - imagedestroy($currentImage); - // image creation fail if(!$success) { @@ -757,14 +717,14 @@ public function setCropPosition($horizontal = 'center', $vertical = 'middle') $vertical = (string) $vertical; // validate horizontal - if(SpoonFilter::getValue($horizontal, array('left', 'center', 'right'), '') == '') + if(SpoonFilter::getValue($horizontal, ['left', 'center', 'right'], '') == '') { if($this->strict) throw new SpoonThumbnailException('The horizontal crop-position "' . $horizontal . '" isn\'t valid.'); return false; } // validte vertical - if(SpoonFilter::getValue($vertical, array('top', 'middle', 'bottom'), '') == '') + if(SpoonFilter::getValue($vertical, ['top', 'middle', 'bottom'], '') == '') { if($this->strict) throw new SpoonThumbnailException('The vertical crop-position "' . $vertical . '" isn\'t valid.'); return false;