Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PES-2296, Check phpcs sniff ValidVariableName #625

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions cli/create-latte-cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@
require_once __DIR__ . '/../../../../wp-includes/rest-api/endpoints/class-wp-rest-controller.php';
require_once __DIR__ . '/../../../../wp-includes/rest-api/class-wp-rest-server.php';

$container = require __DIR__ . '/../bootstrap-cli.php';
$latte_engine = $container->getByType( Engine::class );
$container = require __DIR__ . '/../bootstrap-cli.php';
$latteEngine = $container->getByType( Engine::class );

if ( is_dir( $container->parameters['latteTempFolder'] ) ) {
$files_to_delete = Finder::findFiles( '*' )->from( $container->parameters['latteTempFolder'] );
foreach ( $files_to_delete as $file_to_delete ) {
unlink( $file_to_delete );
$filesToDelete = Finder::findFiles( '*' )->from( $container->parameters['latteTempFolder'] );
foreach ( $filesToDelete as $fileToDelete ) {
unlink( $fileToDelete );
}
}

$finder = Finder::findFiles( '*.latte' )->from( PACKETERY_PLUGIN_DIR . '/template' );
foreach ( $finder as $file ) {
$latte_engine->warmupCache( $file );
$latteEngine->warmupCache( $file );
}
2 changes: 2 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
"build-deps": "bash build-deps.sh",
"check:ec": "vendor/bin/ec .",
"wpify-scoper": "wpify-scoper",
"check:phpcs": "vendor/bin/phpcs",
"fix:phpcbf": "vendor/bin/phpcbf",
"phpstan-72": "phpstan/vendor/bin/phpstan -cphpstan/php72.neon analyse",
"phpstan-74": "phpstan/vendor/bin/phpstan -cphpstan/php74.neon analyse",
"phpstan-80": "phpstan/vendor/bin/phpstan -cphpstan/php80.neon analyse",
Expand Down
10 changes: 5 additions & 5 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
<?xml version="1.0"?>
<ruleset name="WooCommerce Coding Standards">
<description>Packetery WP plugin coding standards ruleset.</description>
<arg name="basepath" value="."/>
<arg name="cache" value="temp/.phpcs-cache"/>
<arg name="colors"/>
<arg name="extensions" value="php"/>
<arg name="parallel" value="20"/>
<arg name="tab-width" value="4"/>
<arg name="encoding" value="utf-8"/>
<arg value="p"/>
<arg value="s"/>
<description>Packetery WP plugin coding standards ruleset.</description>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicitní řádek.


<file>cli</file>
<file>src/Packetery</file>
Expand All @@ -27,6 +37,9 @@
<exclude name="WordPress.NamingConventions.ValidFunctionName.MethodDoubleUnderscore"/>
<exclude name="Squiz.Commenting.FunctionCommentThrowTag.WrongNumber"/>
</rule>
<rule ref="Squiz.NamingConventions.ValidVariableName">
<exclude name="Squiz.NamingConventions.ValidVariableName.PrivateNoUnderscore"/>
</rule>

<rule ref="WordPress.WP.I18n">
<properties>
Expand Down
6 changes: 3 additions & 3 deletions src/Packetery/Core/CoreHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@ public static function trimDecimalPlaces( float $value, int $position ): string
/**
* Returns tracking URL.
*
* @param string $packet_id Packet ID.
* @param string $packetId Packet ID.
*
* @return string
*/
public function get_tracking_url( string $packet_id ): string {
return sprintf( self::TRACKING_URL, rawurlencode( $packet_id ) );
public function get_tracking_url( string $packetId ): string {
return sprintf( self::TRACKING_URL, rawurlencode( $packetId ) );
}

/**
Expand Down
18 changes: 9 additions & 9 deletions src/Packetery/Module/Carrier/Downloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class Downloader {
*
* @var Updater Carrier updater.
*/
private $carrier_updater;
private $carrierUpdater;

/**
* Options provider.
Expand All @@ -46,12 +46,12 @@ class Downloader {
/**
* Downloader constructor.
*
* @param Updater $carrier_updater Carrier updater.
* @param Updater $carrierUpdater Carrier updater.
* @param OptionsProvider $optionsProvider Options provider.
* @param WebRequestClient $webRequestClient HTTP client.
*/
public function __construct( Updater $carrier_updater, OptionsProvider $optionsProvider, WebRequestClient $webRequestClient ) {
$this->carrier_updater = $carrier_updater;
public function __construct( Updater $carrierUpdater, OptionsProvider $optionsProvider, WebRequestClient $webRequestClient ) {
$this->carrierUpdater = $carrierUpdater;
$this->optionsProvider = $optionsProvider;
$this->webRequestClient = $webRequestClient;
}
Expand Down Expand Up @@ -85,8 +85,8 @@ public function run(): array {
'error',
];
}
$validation_result = $this->carrier_updater->validate_carrier_data( $carriers );
if ( ! $validation_result ) {
$validationResult = $this->carrierUpdater->validate_carrier_data( $carriers );
if ( ! $validationResult ) {
// translators: keep %failReason placeholder intact.
$translatedMessage = __( 'Carrier download failed: %failReason Please try again later.', 'packeta' );
return [
Expand All @@ -97,7 +97,7 @@ public function run(): array {
'error',
];
}
$this->carrier_updater->save( $carriers );
$this->carrierUpdater->save( $carriers );
update_option( self::OPTION_LAST_CARRIER_UPDATE, gmdate( DATE_ATOM ) );

return [
Expand Down Expand Up @@ -144,8 +144,8 @@ private function download_json(): string {
* @return array|null
*/
private function get_from_json( string $json ): ?array {
$carriers_data = json_decode( $json, true );
$carriersData = json_decode( $json, true );

return ( $carriers_data['carriers'] ?? null );
return ( $carriersData['carriers'] ?? null );
}
}
30 changes: 15 additions & 15 deletions src/Packetery/Module/Carrier/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function __construct(
* @return bool
*/
public function createOrAlterTable(): bool {
$createTableQuery = 'CREATE TABLE ' . $this->wpdbAdapter->packetery_carrier . ' (
$createTableQuery = 'CREATE TABLE ' . $this->wpdbAdapter->packeteryCarrier . ' (
`id` int(11) NOT NULL,
`name` varchar(255) NOT NULL,
`is_pickup_points` tinyint(1) NOT NULL,
Expand All @@ -88,14 +88,14 @@ public function createOrAlterTable(): bool {
PRIMARY KEY (`id`)
) ' . $this->wpdbAdapter->get_charset_collate();

return $this->wpdbAdapter->dbDelta( $createTableQuery, $this->wpdbAdapter->packetery_carrier );
return $this->wpdbAdapter->dbDelta( $createTableQuery, $this->wpdbAdapter->packeteryCarrier );
}

/**
* Drop table used to store carriers.
*/
public function drop(): void {
$this->wpdbAdapter->query( 'DROP TABLE IF EXISTS `' . $this->wpdbAdapter->packetery_carrier . '`' );
$this->wpdbAdapter->query( 'DROP TABLE IF EXISTS `' . $this->wpdbAdapter->packeteryCarrier . '`' );
}

/**
Expand All @@ -107,7 +107,7 @@ public function drop(): void {
*/
public function hasPickupPoints( int $carrierId ): bool {
return (bool) $this->wpdbAdapter->get_var(
$this->wpdbAdapter->prepare( 'SELECT `is_pickup_points` FROM `' . $this->wpdbAdapter->packetery_carrier . '` WHERE `id` = %d', $carrierId )
$this->wpdbAdapter->prepare( 'SELECT `is_pickup_points` FROM `' . $this->wpdbAdapter->packeteryCarrier . '` WHERE `id` = %d', $carrierId )
);
}

Expand All @@ -122,7 +122,7 @@ public function getById( int $carrierId ): ?array {
return $this->wpdbAdapter->get_row(
$this->wpdbAdapter->prepare(
'SELECT `' . implode( '`, `', self::COLUMN_NAMES ) . '`
FROM `' . $this->wpdbAdapter->packetery_carrier . '` WHERE `id` = %s',
FROM `' . $this->wpdbAdapter->packeteryCarrier . '` WHERE `id` = %s',
$carrierId
),
ARRAY_A
Expand All @@ -140,7 +140,7 @@ public function getByCountry( string $country ): ?array {
return $this->wpdbAdapter->get_results(
$this->wpdbAdapter->prepare(
'SELECT `' . implode( '`, `', self::COLUMN_NAMES ) . '`
FROM `' . $this->wpdbAdapter->packetery_carrier . '` WHERE `country` = %s AND `deleted` = false',
FROM `' . $this->wpdbAdapter->packeteryCarrier . '` WHERE `country` = %s AND `deleted` = false',
$country
),
ARRAY_A
Expand All @@ -155,7 +155,7 @@ public function getByCountry( string $country ): ?array {
public function getActiveCarriers(): ?array {
return $this->wpdbAdapter->get_results(
'SELECT `' . implode( '`, `', self::COLUMN_NAMES ) . '`
FROM `' . $this->wpdbAdapter->packetery_carrier . '` WHERE `deleted` = false',
FROM `' . $this->wpdbAdapter->packeteryCarrier . '` WHERE `deleted` = false',
ARRAY_A
);
}
Expand All @@ -168,7 +168,7 @@ public function getActiveCarriers(): ?array {
public function getAllRawIndexed(): array {
$unIndexedResult = $this->wpdbAdapter->get_results(
'SELECT `' . implode( '`, `', self::COLUMN_NAMES ) . '`
FROM `' . $this->wpdbAdapter->packetery_carrier . '`',
FROM `' . $this->wpdbAdapter->packeteryCarrier . '`',
ARRAY_A
);

Expand All @@ -181,7 +181,7 @@ public function getAllRawIndexed(): array {
* @return bool
*/
public function hasAnyActiveFeedCarrier(): bool {
return (bool) $this->wpdbAdapter->get_var( 'SELECT 1 FROM `' . $this->wpdbAdapter->packetery_carrier . '` WHERE `deleted` = false LIMIT 1' );
return (bool) $this->wpdbAdapter->get_var( 'SELECT 1 FROM `' . $this->wpdbAdapter->packeteryCarrier . '` WHERE `deleted` = false LIMIT 1' );
}

/**
Expand All @@ -190,7 +190,7 @@ public function hasAnyActiveFeedCarrier(): bool {
* @return array
*/
public function getCountries(): array {
return $this->wpdbAdapter->get_col( 'SELECT `country` FROM `' . $this->wpdbAdapter->packetery_carrier . '` WHERE `deleted` = false GROUP BY `country` ORDER BY `country`' );
return $this->wpdbAdapter->get_col( 'SELECT `country` FROM `' . $this->wpdbAdapter->packeteryCarrier . '` WHERE `deleted` = false GROUP BY `country` ORDER BY `country`' );
}

/**
Expand All @@ -200,7 +200,7 @@ public function getCountries(): array {
*/
public function set_as_deleted( array $carrierIdsNotInFeed ): void {
$this->wpdbAdapter->query(
'UPDATE `' . $this->wpdbAdapter->packetery_carrier . '`
'UPDATE `' . $this->wpdbAdapter->packeteryCarrier . '`
SET `deleted` = 1 WHERE `id` IN (' . implode( ',', $carrierIdsNotInFeed ) . ')'
);
}
Expand All @@ -211,16 +211,16 @@ public function set_as_deleted( array $carrierIdsNotInFeed ): void {
* @param array $data Carrier data.
*/
public function insert( array $data ): void {
$this->wpdbAdapter->insert( $this->wpdbAdapter->packetery_carrier, $data );
$this->wpdbAdapter->insert( $this->wpdbAdapter->packeteryCarrier, $data );
}

/**
* Updates carrier data in db.
*
* @param array $data Carrier data.
* @param int $carrier_id Carrier id.
* @param int $carrierId Carrier id.
*/
public function update( array $data, int $carrier_id ): void {
$this->wpdbAdapter->update( $this->wpdbAdapter->packetery_carrier, $data, [ 'id' => $carrier_id ] );
public function update( array $data, int $carrierId ): void {
$this->wpdbAdapter->update( $this->wpdbAdapter->packeteryCarrier, $data, [ 'id' => $carrierId ] );
}
}
46 changes: 23 additions & 23 deletions src/Packetery/Module/Carrier/Updater.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Updater {
*
* @var Repository
*/
private $carrier_repository;
private $carrierRepository;

/**
* Logger.
Expand All @@ -43,12 +43,12 @@ class Updater {
/**
* CarrierUpdater constructor.
*
* @param Repository $carrier_repository Carrier repository.
* @param Repository $carrierRepository Carrier repository.
* @param ILogger $logger Logger.
*/
public function __construct( Repository $carrier_repository, ILogger $logger ) {
$this->carrier_repository = $carrier_repository;
$this->logger = $logger;
public function __construct( Repository $carrierRepository, ILogger $logger ) {
$this->carrierRepository = $carrierRepository;
$this->logger = $logger;
}

/**
Expand Down Expand Up @@ -90,9 +90,9 @@ public function validate_carrier_data( array $carriers ): bool {
* @return array data to store in db
*/
private function carriers_mapper( array $carriers ): array {
$mapped_data = array();
$mappedData = array();

$carrier_boolean_params = array(
$carrierBooleanParams = array(
'is_pickup_points' => 'pickupPoints',
'has_carrier_direct_label' => 'apiAllowed',
'separate_house_number' => 'separateHouseNumber',
Expand All @@ -104,21 +104,21 @@ private function carriers_mapper( array $carriers ): array {
);

foreach ( $carriers as $carrier ) {
$carrier_id = (int) $carrier['id'];
$carrier_data = array(
$carrierId = (int) $carrier['id'];
$carrierData = array(
'name' => $carrier['name'],
'country' => $carrier['country'],
'currency' => $carrier['currency'],
'max_weight' => (float) $carrier['maxWeight'],
'deleted' => false,
);
foreach ( $carrier_boolean_params as $column_name => $param_name ) {
$carrier_data[ $column_name ] = ( 'true' === $carrier[ $param_name ] );
foreach ( $carrierBooleanParams as $columnName => $paramName ) {
$carrierData[ $columnName ] = ( 'true' === $carrier[ $paramName ] );
}
$mapped_data[ $carrier_id ] = $carrier_data;
$mappedData[ $carrierId ] = $carrierData;
}

return $mapped_data;
return $mappedData;
}

/**
Expand All @@ -127,12 +127,12 @@ private function carriers_mapper( array $carriers ): array {
* @param array $carriers Validated data retrieved from API.
*/
public function save( array $carriers ): void {
$mapped_data = $this->carriers_mapper( $carriers );
$carriersInDb = $this->carrier_repository->getAllRawIndexed();
foreach ( $mapped_data as $carrier_id => $carrier ) {
if ( ! empty( $carriersInDb[ $carrier_id ] ) ) {
$this->carrier_repository->update( $carrier, (int) $carrier_id );
$differences = $this->getArrayDifferences( $carriersInDb[ $carrier_id ], $carrier );
$mappedData = $this->carriers_mapper( $carriers );
$carriersInDb = $this->carrierRepository->getAllRawIndexed();
foreach ( $mappedData as $carrierId => $carrier ) {
if ( ! empty( $carriersInDb[ $carrierId ] ) ) {
$this->carrierRepository->update( $carrier, (int) $carrierId );
$differences = $this->getArrayDifferences( $carriersInDb[ $carrierId ], $carrier );
if ( ! empty( $differences ) ) {
$this->addLogEntry(
// translators: %s is carrier name.
Expand All @@ -141,10 +141,10 @@ public function save( array $carriers ): void {
__( 'New parameters', 'packeta' ) . ': ' . implode( ', ', $differences )
);
}
unset( $carriersInDb[ $carrier_id ] );
unset( $carriersInDb[ $carrierId ] );
} else {
$carrier['id'] = $carrier_id;
$this->carrier_repository->insert( $carrier );
$carrier['id'] = $carrierId;
$this->carrierRepository->insert( $carrier );
$this->addLogEntry(
// translators: %s is carrier name.
sprintf( __( 'A new carrier "%s" has been added.', 'packeta' ), $carrier['name'] )
Expand All @@ -153,7 +153,7 @@ public function save( array $carriers ): void {
}

if ( ! empty( $carriersInDb ) ) {
$this->carrier_repository->set_as_deleted( array_keys( $carriersInDb ) );
$this->carrierRepository->set_as_deleted( array_keys( $carriersInDb ) );
foreach ( $carriersInDb as $deletedCarrier ) {
if ( true === (bool) $deletedCarrier['deleted'] ) {
continue;
Expand Down
Loading
Loading