refactor: correct static analyze errors
This commit is contained in:
4
.github/workflows/main.yaml
vendored
4
.github/workflows/main.yaml
vendored
@@ -56,6 +56,10 @@ jobs:
|
||||
APP_ENV: testing
|
||||
run: ./vendor/bin/phpunit --testdox tests/Unit tests/Telegram
|
||||
|
||||
- name: Static Analyzer
|
||||
working-directory: module/oc_telegram_shop/upload/oc_telegram_shop
|
||||
run: ./vendor/bin/phpstan analyse
|
||||
|
||||
phpcs:
|
||||
name: Run PHP_CodeSniffer
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
2
Makefile
2
Makefile
@@ -46,7 +46,7 @@ dev-admin:
|
||||
cd frontend/admin && npm run dev
|
||||
|
||||
lint:
|
||||
docker compose exec -w /module/oc_telegram_shop/upload/oc_telegram_shop web bash -c "./vendor/bin/phpstan analyse src framework"
|
||||
docker compose exec -w /module/oc_telegram_shop/upload/oc_telegram_shop web bash -c "./vendor/bin/phpstan analyse"
|
||||
|
||||
phpcs:
|
||||
docker compose exec -w /module/oc_telegram_shop/upload/oc_telegram_shop web bash -c "./vendor/bin/phpcs --standard=PSR12 bastion framework src"
|
||||
|
||||
@@ -14,7 +14,7 @@ services:
|
||||
deploy:
|
||||
resources:
|
||||
limits:
|
||||
memory: 512M
|
||||
memory: 1G
|
||||
healthcheck:
|
||||
test: [ "CMD", "curl" ,"-f", "http://localhost/index.php?route=extension/tgshop/handle&api_action=health" ]
|
||||
interval: 10s
|
||||
|
||||
@@ -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'),
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace Openguru\OpenCartFramework\Exceptions;
|
||||
|
||||
use Exception;
|
||||
use Throwable;
|
||||
|
||||
class ActionNotFoundException extends Exception implements NonLoggableExceptionInterface
|
||||
{
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
15
module/oc_telegram_shop/upload/oc_telegram_shop/phpstan.neon
Normal file
15
module/oc_telegram_shop/upload/oc_telegram_shop/phpstan.neon
Normal 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
|
||||
@@ -10,7 +10,7 @@ class OcModelCatalogProductAdapter
|
||||
/** @var Proxy|ModelCatalogProduct */
|
||||
private Proxy $model;
|
||||
|
||||
public function __construct(Proxy $model)
|
||||
public function __construct($model)
|
||||
{
|
||||
$this->model = $model;
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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' => [],
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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' => [],
|
||||
|
||||
@@ -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' => [],
|
||||
|
||||
@@ -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' => [
|
||||
|
||||
@@ -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],
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user