Skip to content

Commit

Permalink
Added error directory to checks + php8.4 fix (#4184)
Browse files Browse the repository at this point in the history
* php8.4 fix

* updated php-cs-fixer

* added error directory to workflows

* cs fixes

* phpcbf fixes
  • Loading branch information
sreichel authored Sep 9, 2024
1 parent a324904 commit 1ccc459
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 28 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
strategy:
matrix:
operating-system: [ubuntu-latest]
php-versions: ['7.4', '8.3']
php-versions: ['7.4', '8.4']

steps:
- name: Setup PHP
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/syntax-php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:

strategy:
matrix:
php: ['7.4', '8.3']
php: ['7.4', '8.4']

name: PHP Syntax ${{ matrix.php }}

Expand Down
1 change: 1 addition & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@
PhpCsFixer\Finder::create()
->in([
'app/code/core/Mage/',
'errors/',
'lib/Mage/',
'lib/Magento/',
'lib/Varien/',
Expand Down
1 change: 1 addition & 0 deletions .phpcs.ecg.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<file>install.php</file>
<file>app/Mage.php</file>
<file>app/code/core/Mage/</file>
<file>errors/</file>
<file>lib/Mage/</file>
<file>lib/Magento/</file>
<file>lib/Varien/</file>
Expand Down
1 change: 1 addition & 0 deletions .phpcs.php.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<file>install.php</file>
<file>app/Mage.php</file>
<file>app/code/core/Mage/</file>
<file>errors/</file>
<file>lib/Mage/</file>
<file>lib/Magento/</file>
<file>lib/Varien/</file>
Expand Down
1 change: 1 addition & 0 deletions .phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<file>install.php</file>
<file>app/Mage.php</file>
<file>app/code/core/Mage/</file>
<file>errors/</file>
<file>lib/Mage/</file>
<file>lib/Magento/</file>
<file>lib/Varien/</file>
Expand Down
1 change: 1 addition & 0 deletions .phpstan.dist.neon
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ parameters:
- install.php
- app/Mage.php
- app/code/core/Mage
- errors
- lib/Mage
- lib/Magento
- lib/Varien
Expand Down
48 changes: 23 additions & 25 deletions errors/processor.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@
* @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/

/**
* Error processor
*
*/
/**
* Error processor
*
*/
class Error_Processor
{
const MAGE_ERRORS_LOCAL_XML = 'local.xml';
const MAGE_ERRORS_DESIGN_XML = 'design.xml';
const DEFAULT_SKIN = 'default';
const DEFAULT_TRASH_MODE = 'leave';
const ERROR_DIR = 'errors';
public const MAGE_ERRORS_LOCAL_XML = 'local.xml';
public const MAGE_ERRORS_DESIGN_XML = 'design.xml';
public const DEFAULT_SKIN = 'default';
public const DEFAULT_TRASH_MODE = 'leave';
public const ERROR_DIR = 'errors';

/** @var string */
public $pageTitle;
Expand Down Expand Up @@ -94,10 +94,9 @@ public function __construct()
$this->_reportDir = dirname($this->_errorDir) . '/var/report/';

if (!empty($_SERVER['SCRIPT_NAME'])) {
if (in_array(basename($_SERVER['SCRIPT_NAME'],'.php'), array('404','503','report'))) {
if (in_array(basename($_SERVER['SCRIPT_NAME'], '.php'), ['404','503','report'])) {
$this->_scriptName = dirname($_SERVER['SCRIPT_NAME']);
}
else {
} else {
$this->_scriptName = $_SERVER['SCRIPT_NAME'];
}
}
Expand All @@ -108,7 +107,7 @@ public function __construct()
}

$this->_indexDir = $this->_getIndexDir();
$this->_root = is_dir($this->_indexDir.'app');
$this->_root = is_dir($this->_indexDir . 'app');

$this->_prepareConfig();
if (isset($_SERVER['MAGE_ERRORS_SKIN']) || isset($_GET['skin'])) {
Expand Down Expand Up @@ -150,7 +149,7 @@ public function processReport()
$this->reportAction = $this->_config->action;
$this->_setReportUrl();

if($this->reportAction === 'email') {
if ($this->reportAction === 'email') {
$this->showSendForm = true;
$this->sendReport();
}
Expand All @@ -159,7 +158,7 @@ public function processReport()

public function getSkinUrl(): string
{
return $this->getBaseUrl() . self::ERROR_DIR. '/' . $this->_config->skin . '/';
return $this->getBaseUrl() . self::ERROR_DIR . '/' . $this->_config->skin . '/';
}

/**
Expand All @@ -184,7 +183,7 @@ public function getHostUrl(): string

if (!empty($_SERVER['SERVER_PORT'])
&& preg_match('/\d+/', $_SERVER['SERVER_PORT'])
&& !in_array($_SERVER['SERVER_PORT'], array(80, 433))
&& !in_array($_SERVER['SERVER_PORT'], [80, 433])
) {
$url .= ':' . $_SERVER['SERVER_PORT'];
}
Expand All @@ -195,7 +194,7 @@ public function getBaseUrl(bool $param = false): string
{
$path = $this->_scriptName;

if($param && !$this->_root) {
if ($param && !$this->_root) {
$path = dirname($path);
}

Expand All @@ -215,7 +214,7 @@ protected function _getIndexDir(): string
{
$documentRoot = '';
if (!empty($_SERVER['DOCUMENT_ROOT'])) {
$documentRoot = rtrim($_SERVER['DOCUMENT_ROOT'],'/');
$documentRoot = rtrim($_SERVER['DOCUMENT_ROOT'], '/');
}
return dirname($documentRoot . $this->_scriptName) . '/';
}
Expand Down Expand Up @@ -318,7 +317,7 @@ protected function _renderPage($template)
protected function _getFilePath(string $file, $directories = null)
{
if ($directories === null) {
$directories = array();
$directories = [];

if (!$this->_root) {
$directories[] = $this->_indexDir . self::ERROR_DIR . '/';
Expand All @@ -345,10 +344,10 @@ protected function _getTemplatePath(string $template)
$directories = [];

if (!$this->_root) {
$directories[] = $this->_indexDir . self::ERROR_DIR. '/'. $this->_config->skin . '/';
$directories[] = $this->_indexDir . self::ERROR_DIR . '/' . $this->_config->skin . '/';

if ($this->_config->skin !== self::DEFAULT_SKIN) {
$directories[] = $this->_indexDir . self::ERROR_DIR . '/'. self::DEFAULT_SKIN . '/';
$directories[] = $this->_indexDir . self::ERROR_DIR . '/' . self::DEFAULT_SKIN . '/';
}
}

Expand All @@ -368,8 +367,7 @@ protected function _setReportData(array $reportData)
if (isset($reportData['url'])) {
$this->reportData['url'] = $this->getHostUrl()
. htmlspecialchars($reportData['url'], ENT_COMPAT | ENT_HTML401, 'UTF-8');
}
else {
} else {
$this->reportData['url'] = '';
}

Expand Down Expand Up @@ -424,7 +422,7 @@ public function loadReport(int $reportId)
}

$reportContent = file_get_contents($this->_reportFile);
if (!preg_match('/[oc]:[+\-]?\d+:"/i', $reportContent )) {
if (!preg_match('/[oc]:[+\-]?\d+:"/i', $reportContent)) {
$reportData = unserialize($reportContent, ['allowed_classes' => false]);
}
if (is_array($reportData)) {
Expand Down Expand Up @@ -501,7 +499,7 @@ protected function _validate(): bool
/**
* @return void
*/
protected function _setSkin(string $value, stdClass $config = null)
protected function _setSkin(string $value, ?stdClass $config = null)
{
if (preg_match('/^[a-z0-9_]+$/i', $value)
&& is_dir($this->_indexDir . self::ERROR_DIR . '/' . $value)
Expand Down
4 changes: 3 additions & 1 deletion errors/report.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
* @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/

if ($_SERVER['SCRIPT_FILENAME'] == __FILE__ && (!isset($_GET['id']) || strlen($_GET['id']) == 0)) die("Missing parameter: id");
if ($_SERVER['SCRIPT_FILENAME'] == __FILE__ && (!isset($_GET['id']) || strlen($_GET['id']) == 0)) {
die('Missing parameter: id');
}

require_once 'processor.php';

Expand Down

0 comments on commit 1ccc459

Please sign in to comment.