Skip to content

Commit

Permalink
patch
Browse files Browse the repository at this point in the history
  • Loading branch information
AnourValar committed Sep 17, 2023
1 parent be2a603 commit 99f8d3c
Show file tree
Hide file tree
Showing 21 changed files with 104 additions and 25 deletions.
11 changes: 11 additions & 0 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

$finder = PhpCsFixer\Finder::create()
->exclude('vendor')
->in(__DIR__);

$config = new PhpCsFixer\Config();
return $config->setRules([
'@PSR12' => true,
])
->setFinder($finder);
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
},
"require-dev": {
"phpunit/phpunit": "^10.0",
"orchestra/testbench": "^8.6"
"orchestra/testbench": "^8.6",
"phpstan/phpstan": "^1.10",
"friendsofphp/php-cs-fixer": "^3.26",
"squizlabs/php_codesniffer": "^3.7"
},
"autoload": {
"psr-4": {"AnourValar\\LaravelAtom\\": "src/"}
Expand Down
36 changes: 36 additions & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?xml version="1.0"?>
<!-- @see https://pear.php.net/manual/en/package.php.php-codesniffer.annotated-ruleset.php -->
<ruleset name="PHPCS Rules">

<description>PHPCS ruleset</description>

<file>src</file>
<file>tests</file>

<!-- Show progress of the run -->
<arg value= "p"/>

<!-- Show sniff codes in all reports -->
<arg value= "s"/>

<!-- Our base rule: set to PSR12 -->
<rule ref="PSR12">
<exclude name="PSR12.Operators.OperatorSpacing.NoSpaceBefore"/>
<exclude name="PSR12.Operators.OperatorSpacing.NoSpaceAfter"/>
<exclude name="PSR12.Traits.UseDeclaration.MultipleImport"/>
<exclude name="Generic.Files.LineLength.TooLong"/>
<exclude name="PSR2.Methods.FunctionClosingBrace.SpacingBeforeClose"/>
<exclude name="PSR12.Classes.OpeningBraceSpace.Found"/>
<exclude name="Squiz.WhiteSpace.ControlStructureSpacing.SpacingAfterOpen"/>
<exclude name="Squiz.WhiteSpace.ControlStructureSpacing.SpacingBeforeClose"/>
</rule>

<rule ref="PSR1.Methods.CamelCapsMethodName.NotCamelCaps">
<exclude-pattern>tests/</exclude-pattern>
</rule>

<rule ref="Internal.NoCodeFound">
<exclude-pattern>tests/</exclude-pattern>
</rule>

</ruleset>
32 changes: 32 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
parameters:

paths:
- src
- tests

# The level 9 is the highest level
level: 5

ignoreErrors:
- '#Call to static method#'
- '#Unsafe usage of new static\(\)#'
- '#Method AnourValar\\LaravelAtom\\Helpers\\NumberHelper\:\:encodeMultiple\(\) should return int\|null but returns float#'
- '#Result of method AnourValar\\LaravelAtom\\Service\:\:lock\(\) \(void\) is used\.#'
- '#Parameter \#1 \$a#'
- '#Parameter \#4 \$d#'
- '#Call to an undefined method#'
- '#If condition is always true#'
- '#Call to an undefined static#'

excludePaths:

checkFunctionNameCase: true
checkInternalClassCaseSensitivity: true
checkAlwaysTrueInstanceof: true
reportMaybesInMethodSignatures: true
reportStaticMethodSignatures: true
checkUninitializedProperties: true
checkDynamicProperties: true
reportAlwaysTrueInLastCondition: true
reportWrongPhpDocTypeInVarTag: true
checkMissingCallableSignature: true
2 changes: 1 addition & 1 deletion src/ArrayAccessMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,6 @@ public function offsetUnset($offset): void
*/
public function offsetGet($offset): mixed
{
return ( $this->data[$offset] ?? ($this->instanceInsteadOfNull ? (new static([], true)) : null) );
return ($this->data[$offset] ?? ($this->instanceInsteadOfNull ? (new static([], true)) : null));
}
}
1 change: 0 additions & 1 deletion src/Exceptions/OptimisticTransactionException.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@

class OptimisticTransactionException extends \Exception
{

}
12 changes: 6 additions & 6 deletions src/Helpers/DateHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class DateHelper
* @param string|null $default
* @return string|null
*/
function formatDate($date, mixed $time = true, string $timezoneClient = 'UTC', ?string $default = null): ?string
public function formatDate($date, mixed $time = true, string $timezoneClient = 'UTC', ?string $default = null): ?string
{
if (! $date) {
return $default;
Expand All @@ -25,7 +25,7 @@ function formatDate($date, mixed $time = true, string $timezoneClient = 'UTC', ?

if (! $date instanceof \Carbon\CarbonInterface) {
//try {
$date = \Date::parse($date);
$date = \Date::parse($date);
//} catch (\Carbon\Exceptions\InvalidFormatException $e) {
// return $default;
//}
Expand Down Expand Up @@ -54,15 +54,15 @@ function formatDate($date, mixed $time = true, string $timezoneClient = 'UTC', ?
* @param string|null $default
* @return string|null
*/
function formatDateTime($date, string $timezoneClient = 'UTC', ?string $default = null): ?string
public function formatDateTime($date, string $timezoneClient = 'UTC', ?string $default = null): ?string
{
if (! $date) {
return $default;
}

if (! $date instanceof \Carbon\CarbonInterface) {
//try {
$date = \Date::parse($date);
$date = \Date::parse($date);
//} catch (\Carbon\Exceptions\InvalidFormatException $e) {
// return $default;
//}
Expand All @@ -79,15 +79,15 @@ function formatDateTime($date, string $timezoneClient = 'UTC', ?string $default
* @param string|null $default
* @return string|null
*/
function formatTime($date, string $timezoneClient = 'UTC', ?string $default = null): ?string
public function formatTime($date, string $timezoneClient = 'UTC', ?string $default = null): ?string
{
if (! $date) {
return $default;
}

if (! $date instanceof \Carbon\CarbonInterface) {
//try {
$date = \Date::parse($date);
$date = \Date::parse($date);
//} catch (\Carbon\Exceptions\InvalidFormatException $e) {
// return $default;
//}
Expand Down
2 changes: 1 addition & 1 deletion src/Helpers/NumberHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function formatNumber(?float $number, int $decimals = 0, ?string $default
* Amount as text
*
* @param int|float $amount
* @param bool $ucFirst
* @param bool $ucfirst
* @return string
*/
public function spellout(int|float $amount, bool $ucfirst = true): string
Expand Down
2 changes: 1 addition & 1 deletion src/Helpers/StringHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function formatPhone(?string $phone): ?string
*/
public function canonizeEmail(?string $email): string
{
return trim( mb_strtolower($email) );
return trim(mb_strtolower($email));
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/Http/Middleware/Web/Select2.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ private function convertResponse(\Symfony\Component\HttpFoundation\Response &$re
{
$content = $response->getOriginalContent();

if (! $content instanceof \Illuminate\Pagination\LengthAwarePaginator
if (
! $content instanceof \Illuminate\Pagination\LengthAwarePaginator
&& ! $content instanceof \Illuminate\Pagination\CursorPaginator
&& ! $content instanceof \Illuminate\Pagination\Paginator
&& $response->isSuccessful()
Expand Down
2 changes: 1 addition & 1 deletion src/Mapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public static function from(array|object $data): static
*/
public function toArray(): array
{
return $this->resolveToArray((array) $this, static::getRules(new \ReflectionClass(static::class)));
return $this->resolveToArray((array) $this, static::getRules(new \ReflectionClass(static::class)));
}

/**
Expand Down
1 change: 0 additions & 1 deletion src/Mapper/Exclude.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@
#[Attribute(Attribute::TARGET_PROPERTY)]
class Exclude
{

}
1 change: 0 additions & 1 deletion src/Mapper/MappingSnakeCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@
#[Attribute(Attribute::TARGET_CLASS | Attribute::TARGET_PROPERTY)]
class MappingSnakeCase
{

}
1 change: 0 additions & 1 deletion src/Mapper/Optional.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@

class Optional
{

}
6 changes: 3 additions & 3 deletions src/Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public function lock(): void
$table = $this->config['locks']['table'];

$class = $this->config['locks']['strategies'][$this->config['locks']['strategy']];
(new $class)->lock($sha1, $connection, $table);
(new $class())->lock($sha1, $connection, $table);

if ($this->lockHook) {
($this->lockHook)($sha1, func_get_args());
Expand Down Expand Up @@ -289,7 +289,7 @@ protected function cleanUp(\Illuminate\Database\Connection $connection, string $
*/
protected function shouldCommit($connection)
{
return (! (\DB::connection($connection)->transactionLevel() - $this->transactionZeroLevel));
return (! (\DB::connection($connection)->transactionLevel() - $this->transactionZeroLevel));
}

/**
Expand All @@ -298,6 +298,6 @@ protected function shouldCommit($connection)
*/
protected function shouldRollBack($connection)
{
return (! (\DB::connection($connection)->transactionLevel() - $this->transactionZeroLevel));
return (! (\DB::connection($connection)->transactionLevel() - $this->transactionZeroLevel));
}
}
2 changes: 1 addition & 1 deletion tests/Mappers/ArrayOfMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class ArrayOfMapper extends Mapper
{
public function __construct(
public function __construct(
#[ArrayOf(ExcludeMapper::class)]
public array $excludes,
) {
Expand Down
2 changes: 1 addition & 1 deletion tests/Mappers/ComplexMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class ComplexMapper extends Mapper
{
public function __construct(
public function __construct(
public int $userId,
#[Mapping('boss_id')]
public int $managerId,
Expand Down
2 changes: 1 addition & 1 deletion tests/Mappers/ExcludeMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class ExcludeMapper extends Mapper
{
public function __construct(
public function __construct(
#[Exclude]
public string $a,
public string $b,
Expand Down
2 changes: 1 addition & 1 deletion tests/Mappers/ModeMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#[MappingSnakeCase]
class ModeMapper extends Mapper
{
public function __construct(
public function __construct(
public int $userId,
#[DefaultValue(3)]
public int $managerId,
Expand Down
2 changes: 1 addition & 1 deletion tests/Mappers/NestedMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

class NestedMapper extends Mapper
{
public function __construct(
public function __construct(
public string|Optional $a,
) {

Expand Down
2 changes: 1 addition & 1 deletion tests/Mappers/SimpleMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class SimpleMapper extends Mapper
{
public function __construct(
public function __construct(
public string $a,
public $b,
public ?string $c = null,
Expand Down

0 comments on commit 99f8d3c

Please sign in to comment.