Skip to content

Commit

Permalink
Support customized local configuration files for PHPStan and PHPUnit …
Browse files Browse the repository at this point in the history
…(#502)

* Support customized local configuration files for PHPStan and PHPUnit

* Optimize

* Fix return type declarations in Kafka and Log facades

* Refactor array and collection mixins

* Update type hint for process method in TaskHandleListener

* Update CacheInterface and Cache class

* Refactor ParameterParser class by removing unused code

* Refactor Etcd and Nacos drivers, and fix EnvWriter return statement

* Fix type hinting in exception handling functions

* Fix column value retrieval in FastPaginate.php

* Refactor validation rules in ValidationAspect.php

* Update helper functions and fix deprecated functions

* Refactor log writer to use null coalescing operator for default values

* Fix code formatting and remove unused code

* Update variable type in ResponseSequence class and fix factory function in Functions.php

* Fix code inconsistencies and improve code readability

* Update phpstan.neon.dist to include phpstan-baseline.neon

This commit updates the phpstan.neon.dist file to include the phpstan-baseline.neon file. The previous include statement for vendor/phpstan/phpstan-deprecation-rules/rules.neon has been commented out. This change ensures that the phpstan-baseline.neon file is included in the analysis performed by vendor/bin/phpstan.

* Update PHPStan configuration file

* Fix isInstanceCall method logic

* Refactor access log message formatting

---------

Co-authored-by: Deeka Wong <8337659+huangdijia@users.noreply.github.com>
  • Loading branch information
huangdijia and huangdijia committed Dec 20, 2023
1 parent 03a9a9a commit ec4f734
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 22 deletions.
2 changes: 2 additions & 0 deletions src/Command/Functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@

namespace FriendsOfHyperf\Helpers\Command;

use Exception;
use Hyperf\Contract\ApplicationInterface;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\NullOutput;
use TypeError;

use function FriendsOfHyperf\Helpers\di;

Expand Down
33 changes: 11 additions & 22 deletions src/Functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Carbon\Carbon;
use Closure;
use Countable;
use DateTimeZone;
use Exception;
use FriendsOfHyperf\AsyncTask\Task as AsyncTask;
use FriendsOfHyperf\AsyncTask\TaskInterface as AsyncTaskInterface;
Expand All @@ -35,6 +36,7 @@
use Hyperf\Logger\LoggerFactory;
use Hyperf\Stringable\Str;
use Hyperf\Validation\Contract\ValidatorFactoryInterface;
use InvalidArgumentException;
use longlang\phpkafka\Producer\ProduceMessage;
use Psr\Container\ContainerInterface;
use Psr\EventDispatcher\EventDispatcherInterface;
Expand Down Expand Up @@ -105,7 +107,6 @@ function blank($value): bool
*
* If an array is passed, we'll assume you want to put to the cache.
*
* @param dynamic key|key,default|data,expiration|null
* @return CacheInterface|mixed
* @throws Exception
*/
Expand Down Expand Up @@ -186,18 +187,15 @@ function di(string $abstract = null, array $parameters = [])
}

if (is_null($abstract)) {
throw new \InvalidArgumentException('Invalid argument $abstract');
throw new InvalidArgumentException('Invalid argument $abstract');
}

return new $abstract(...array_values($parameters));
}

/**
* @param AsyncTaskInterface|Closure|JobInterface|ProduceMessage|ProducerMessageInterface $job
* @param AsyncTaskInterface|Closure|JobInterface|ProduceMessage|ProducerMessageInterface|object $job
* @return bool
* @throws TypeError
* @throws InvalidDriverException
* @throws InvalidArgumentException
*/
function dispatch($job, ...$arguments)
{
Expand All @@ -221,14 +219,13 @@ function dispatch($job, ...$arguments)
->getProducer((string) ($arguments[0] ?? 'default'))
->sendBatch([$job]),
$job instanceof AsyncTaskInterface => AsyncTask::deliver($job, ...$arguments),
default => throw new \InvalidArgumentException('Not Support job type.')
default => throw new InvalidArgumentException('Not Support job type.')
};
}

/**
* @param mixed $environments
* @return bool|Environment
* @throws TypeError
*/
function environment(...$environments)
{
Expand Down Expand Up @@ -267,7 +264,6 @@ function filled($value): bool

/**
* @param string|Stringable $message
* @throws TypeError
*/
function info($message, array $context = [], bool $backtrace = false)
{
Expand All @@ -276,13 +272,11 @@ function info($message, array $context = [], bool $backtrace = false)
$context['backtrace'] = sprintf('%s:%s', $traces[0]['file'], $traces[0]['line']);
}

return logs()->info($message, $context);
logs()->info($message, $context);
}

/**
* @param string|Stringable|null $message
* @return LoggerInterface|void
* @throws TypeError
*/
function logger($message = null, array $context = [], bool $backtrace = false)
{
Expand All @@ -292,15 +286,12 @@ function logger($message = null, array $context = [], bool $backtrace = false)

if ($backtrace) {
$traces = debug_backtrace();
$context['backtrace'] = sprintf('%s:%s', $traces['file'], $traces['line']);
$context['backtrace'] = array_map(fn ($trace) => sprintf('%s:%s', $trace['file'], $trace['line']), $traces);
}

return logs()->debug($message, $context);
logs()->debug($message, $context);
}

/**
* @throws TypeError
*/
function logs(string $name = 'hyperf', string $group = 'default'): LoggerInterface
{
return di(LoggerFactory::class)->get($name, $group);
Expand Down Expand Up @@ -378,7 +369,6 @@ function resolve(string|callable $abstract, array $parameters = [])
* @param array|string|null $key
* @param mixed $default
* @return array|mixed|RequestInterface
* @throws TypeError
*/
function request($key = null, $default = null)
{
Expand Down Expand Up @@ -445,7 +435,8 @@ function session($key = null, $default = null)
}

if (is_array($key)) {
return $session->put($key);
$session->put($key);
return;
}

return $session->get($key, $default);
Expand All @@ -454,7 +445,7 @@ function session($key = null, $default = null)
/**
* Create a new Carbon instance for the current date.
*
* @param \DateTimeZone|string|null $tz
* @param DateTimeZone|string|null $tz
*/
function today($tz = null): Carbon
{
Expand Down Expand Up @@ -512,7 +503,6 @@ function throw_unless($condition, $exception, ...$parameters)
/**
* Create a new Validator instance.
* @return ValidatorFactoryInterface|ValidatorInterface
* @throws TypeError
*/
function validator(array $data = [], array $rules = [], array $messages = [], array $customAttributes = [])
{
Expand Down Expand Up @@ -540,7 +530,6 @@ function when($expr, $value = null, $default = null)

/**
* Get client IP.
* @throws TypeError
*/
function get_client_ip(): string
{
Expand Down

0 comments on commit ec4f734

Please sign in to comment.