refactor: correct static analyze errors

This commit is contained in:
2025-12-01 18:04:54 +03:00
parent 27c99d9966
commit 5fe4aac7eb
20 changed files with 41 additions and 123 deletions

View File

@@ -18,6 +18,12 @@ class StatsHandler
public function getDashboardStats(): JsonResponse
{
$data = [
'orders_count' => 0,
'orders_total_amount' => 0,
'customers_count' => 0,
];
$ordersTotalAmount = $this->builder->newQuery()
->select([
new RawExpression('COUNT(DISTINCT orders.order_id) AS orders_total_count'),

View File

@@ -1,62 +0,0 @@
<?php
namespace Openguru\OpenCartFramework\Cache;
use Openguru\OpenCartFramework\QueryBuilder\Connections\ConnectionInterface;
class DatabaseCache implements CacheInterface
{
private $connection;
private $table;
public function __construct(ConnectionInterface $connection, string $table)
{
$this->connection = $connection;
$this->table = $table;
}
public function get(string $key)
{
$cache = $this->connection->select(
"
SELECT result
FROM $this->table
WHERE cache_key = :key AND (expires_at IS NULL OR expires_at > NOW())
",
[':key' => $key]
);
return $cache ? unserialize($cache[0]['result'], ['allowed_classes' => true]) : null;
}
public function set(string $key, $value, ?int $ttlSeconds = null): void
{
$this->connection->statement("DELETE FROM $this->table WHERE expires_at IS NOT NULL AND expires_at <= NOW()");
$expiresAt = $ttlSeconds ? date('Y-m-d H:i:s', time() + $ttlSeconds) : null;
$sql = <<<SQL
INSERT INTO $this->table (cache_key, result, expires_at)
VALUES (:key, :result, :expiresAt)
ON DUPLICATE KEY UPDATE
result = VALUES(result),
expires_at = VALUES(expires_at)
SQL;
$this->connection->statement($sql, [
':key' => $key,
':result' => serialize($value),
':expiresAt' => $expiresAt,
]);
}
public function delete(string $key): void
{
$this->connection->statement("DELETE FROM $this->table WHERE cache_key = :key", [':key' => $key]);
}
public function clear(): void
{
$this->connection->truncateTable($this->table);
}
}

View File

@@ -1,44 +0,0 @@
<?php
namespace Openguru\OpenCartFramework\Cache;
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
class SymfonyFilesystemCache implements CacheInterface
{
private FilesystemAdapter $cache;
public function __construct(string $namespace = 'app.cache', int $defaultLifetime = 0, ?string $cacheDir = null)
{
$this->cache = new FilesystemAdapter($namespace, $defaultLifetime, $cacheDir);
}
public function get(string $key)
{
$item = $this->cache->getItem($key);
return $item->isHit() ? $item->get() : null;
}
public function set(string $key, $value, ?int $ttlSeconds = null): void
{
$item = $this->cache->getItem($key);
$item->set($value);
if ($ttlSeconds) {
$item->expiresAfter($ttlSeconds);
}
$this->cache->save($item);
}
public function delete(string $key): void
{
$this->cache->deleteItem($key);
}
public function clear(): void
{
$this->cache->clear();
}
}

View File

@@ -62,11 +62,8 @@ class Container implements ContainerInterface
/**
* @template T
* @param string $id
* @param class-string<T> $id
* @return T
* @psalm-param class-string<T>|string $id
* @psalm-suppress MoreSpecificImplementedParamType
*
*/
public function get(string $id)
{

View File

@@ -3,6 +3,7 @@
namespace Openguru\OpenCartFramework\Exceptions;
use Exception;
use Throwable;
class ActionNotFoundException extends Exception implements NonLoggableExceptionInterface
{

View File

@@ -42,7 +42,7 @@ class ImageTool implements ImageToolInterface
return null; // безопасность
}
$extless = utf8_substr($filename, 0, utf8_strrpos($filename, '.'));
$extless = substr($filename, 0, strrpos($filename, '.'));
$imageNew = 'cache/' . $extless . '-' . $width . 'x' . $height . '.' . $format;
$fullNewPath = $this->imageDir . $imageNew;
@@ -102,7 +102,7 @@ class ImageTool implements ImageToolInterface
return null; // безопасность
}
$extless = utf8_substr($path, 0, utf8_strrpos($path, '.'));
$extless = substr($path, 0, strrpos($path, '.'));
$imageNew = 'cache/' . $extless . '-' . $width . 'x' . $height . '.' . $format;
$fullNewPath = $this->imageDir . $imageNew;

View File

@@ -29,6 +29,7 @@ use Url;
* @property ModelSettingSetting $model_setting_setting
* @property ModelDesignBanner $model_design_banner
* @property ModelCatalogCategory $model_catalog_category
* @property Registry $registry
*/
class OcRegistryDecorator
{

View File

@@ -0,0 +1,15 @@
parameters:
level: 1
paths:
- src
- bastion
- framework
scanDirectories:
- /web/upload/system
scanFiles:
- /web/upload/config.php
- /web/upload/admin/config.php
inferPrivatePropertyTypeFromConstructor: true

View File

@@ -10,7 +10,7 @@ class OcModelCatalogProductAdapter
/** @var Proxy|ModelCatalogProduct */
private Proxy $model;
public function __construct(Proxy $model)
public function __construct($model)
{
$this->model = $model;
}

View File

@@ -14,7 +14,7 @@ class ProductAttribute extends BaseRule
public static function initWithDefaults(): BaseRule
{
return new static(static::NAME, [
return new self(static::NAME, [
'product_attribute' => new Criterion(static::CRITERIA_OPTION_PRODUCT_ATTRIBUTE, [
'attribute_id' => null,
'operator' => static::CRITERIA_OPERATOR_CONTAINS,

View File

@@ -13,7 +13,7 @@ class ProductCategories extends BaseRule
public static function initWithDefaults(): BaseRule
{
return new static(static::NAME, [
return new self(static::NAME, [
'product_category_ids' => new Criterion(static::CRITERIA_OPTION_PRODUCT_CATEGORIES, [
'operator' => static::CRITERIA_OPERATOR_CONTAINS,
'value' => [],

View File

@@ -14,7 +14,7 @@ class ProductCategory extends BaseRule
public static function initWithDefaults(): BaseRule
{
return new static(static::NAME, [
return new self(static::NAME, [
'product_category_id' => new Criterion(static::CRITERIA_OPTION_PRODUCT_CATEGORIES, [
'operator' => static::CRITERIA_OPERATOR_CONTAINS,
'value' => null,

View File

@@ -12,7 +12,7 @@ class ProductManufacturer extends BaseRule
public static function initWithDefaults(): BaseRule
{
return new static(static::NAME, [
return new self(static::NAME, [
'product_manufacturer_ids' => new Criterion(static::CRITERIA_OPTION_PRODUCT_MANUFACTURER, [
'operator' => static::CRITERIA_OPERATOR_CONTAINS,
'value' => [],

View File

@@ -14,7 +14,7 @@ class ProductModel extends BaseRule
public static function initWithDefaults(): BaseRule
{
return new static(static::NAME, [
return new self(static::NAME, [
'product_model' => new Criterion(static::CRITERIA_OPTION_PRODUCT_MODEL, [
'operator' => static::CRITERIA_OPERATOR_CONTAINS,
'value' => [],

View File

@@ -20,7 +20,7 @@ class ProductPrice extends BaseRule
public static function initWithDefaults(): BaseRule
{
return new static(static::NAME, [
return new self(static::NAME, [
'product_price' => new Criterion(static::CRITERIA_OPTION_NUMBER, [
'operator' => static::CRITERIA_OPERATOR_GREATER_OR_EQUAL,
'value' => [

View File

@@ -17,7 +17,7 @@ class ProductQuantity extends BaseRule
public static function initWithDefaults(): BaseRule
{
return new static(static::NAME, [
return new self(static::NAME, [
'product_quantity' => new Criterion(static::CRITERIA_OPTION_NUMBER, [
'operator' => static::CRITERIA_OPERATOR_GREATER_OR_EQUAL,
'value' => [0, null],

View File

@@ -14,7 +14,7 @@ class ProductStatus extends BaseRule
public static function initWithDefaults(): BaseRule
{
return new static(static::NAME, [
return new self(static::NAME, [
'product_status' => new Criterion(static::CRITERIA_OPTION_BOOLEAN, [
'operator' => static::CRITERIA_OPERATOR_EQUALS,
'value' => true,