Skip to content

Commit

Permalink
Merge pull request #266 from bowphp/feat-integrate-queue-adapters
Browse files Browse the repository at this point in the history
formatting
  • Loading branch information
papac authored Sep 23, 2023
2 parents 291b695 + dcf099f commit 0e1b454
Show file tree
Hide file tree
Showing 23 changed files with 90 additions and 68 deletions.
17 changes: 8 additions & 9 deletions src/Container/Action.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,15 +214,13 @@ public function call(callable|string|array $actions, ?array $param = null): mixe
if (!array_key_exists($middleware, $this->middlewares)) {
throw new RouterException(
sprintf('%s is not define middleware.', $middleware),
E_ERROR
);
}

// We check if the defined middleware is a valid middleware.
if (!class_exists($this->middlewares[$middleware])) {
throw new RouterException(
sprintf('%s is not a middleware class.', $middleware),
E_ERROR
);
}

Expand All @@ -243,7 +241,8 @@ public function call(callable|string|array $actions, ?array $param = null): mixe
case is_string($response):
case is_array($response):
case is_object($response):
case $response instanceof \Iterable:
case is_iterable($response):
case $response instanceof \Iterator:
case $response instanceof ResponseInterface:
return $response;
case $response instanceof Model || $response instanceof Collection:
Expand Down Expand Up @@ -315,19 +314,19 @@ private function dispatchControllers(array $functions, array $params): mixed
/**
* Successively launches a function list.
*
* @param array|callable $function
* @param array $arg
* @param array|callable|string $function
* @param array $arguments
* @return mixed
* @throws ReflectionException
*/
public function execute(array|callable $function, array $arg): mixed
public function execute(array|callable|string $function, array $arguments): mixed
{
if (is_callable($function)) {
return call_user_func_array($function, $arg);
return call_user_func_array($function, $arguments);
}

if (is_array($function)) {
return call_user_func_array($function, $arg);
return call_user_func_array($function, $arguments);
}

// We launch the controller loader if $cb is a String
Expand All @@ -340,7 +339,7 @@ public function execute(array|callable $function, array $arg): mixed
if (is_array($controller)) {
return call_user_func_array(
$controller['action'],
array_merge($controller['injection'], $arg)
array_merge($controller['injection'], $arguments)
);
}

Expand Down
16 changes: 8 additions & 8 deletions src/Container/Capsule.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,27 +145,27 @@ public function bind(string $key, callable $value)
* Register the instance of a class
*
* @param string $key
* @param Closure $value
*
* @param Closure|callable $value
* @return void
*/
public function factory($key, \Closure $value)
public function factory($key, Closure|callable $value)
{
$this->factories[$key] = $value;
}

/**
* Saves the instance of a class
*
* @param string $key
* @param string $key
* @param mixed $instance
*
* @return void
*/
public function instance($key, $instance)
public function instance(string $key, mixed $instance): void
{
if (!is_object($instance)) {
throw new InvalidArgumentException('Parameter [2] is invalid');
throw new InvalidArgumentException(
"The parameter $instance must be an object."
);
}

$this->instances[$key] = $instance;
Expand All @@ -178,7 +178,7 @@ public function instance($key, $instance)
* @return mixed
* @throws
*/
private function resolve($key)
private function resolve($key): mixed
{
$reflection = new ReflectionClass($key);

Expand Down
1 change: 0 additions & 1 deletion src/Database/QueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

use Bow\Database\Connection\AbstractConnection;
use PDO;
use stdClass;
use PDOStatement;
use Bow\Support\Str;
use Bow\Support\Util;
Expand Down
6 changes: 4 additions & 2 deletions src/Http/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ private function __construct()
try {
$data = json_decode(file_get_contents("php://input"), true, 1024, JSON_THROW_ON_ERROR);
} catch (\Throwable $e) {
throw new BadRequestException("Invalid JSON syntax");
throw new BadRequestException(
"The request json payload is invalid: " . $e->getMessage(),
);
}
$this->input = array_merge((array) $data, $_GET);
} else {
Expand Down Expand Up @@ -649,7 +651,7 @@ public function getBag(string $name)
/**
* Set the shared value in request bags
*
* @param Array<mixed> $bags
* @param array $bags
* @return mixed
*/
public function setBags(array $bags)
Expand Down
6 changes: 3 additions & 3 deletions src/Http/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -237,9 +237,9 @@ public function addHeaders(array $headers): Response
/**
* Download the given file as an argument
*
* @param string $file
* @param null $filename
* @param array $headers
* @param string $file
* @param ?string $filename
* @param array $headers
* @return string
*/
public function download(
Expand Down
6 changes: 3 additions & 3 deletions src/Http/ServerAccessControl.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,11 @@ public function allowCredentials(): ServerAccessControl
/**
* Active Access-control-Max-Age
*
* @param string $excepted
* @param float|int $excepted
* @return ServerAccessControl
* @throws ServerAccessControlException
*/
public function maxAge(string $excepted): ServerAccessControl
public function maxAge(float|int $excepted): ServerAccessControl
{
if (!is_numeric($excepted)) {
throw new ServerAccessControlException(
Expand All @@ -123,7 +123,7 @@ public function maxAge(string $excepted): ServerAccessControl
);
}

return $this->push('Access-Control-Max-Age', $excepted);
return $this->push('Access-Control-Max-Age', (string) $excepted);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Http/UploadFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ public function __construct(array $file)
/**
* Get the file extension
*
* @return string
* @return ?string
*/
public function getExtension(): string
public function getExtension(): ?string
{
if (!isset($this->file['name'])) {
return null;
Expand Down
6 changes: 3 additions & 3 deletions src/Mail/Driver/SmtpDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,9 @@ private function disconnect()
/**
* Read the current connection stream.
*
* @return string
* @return int
*/
private function read()
private function read(): int
{
$s = null;

Expand All @@ -255,7 +255,7 @@ private function read()
* @param ?string $message
*
* @throws SmtpException
* @return string
* @return string|int|null
*/
private function write(string $command, ?int $code = null, ?string $message = null)
{
Expand Down
12 changes: 11 additions & 1 deletion src/Mail/Mail.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,18 @@ public static function configure(array $config = []): MailDriverInterface
static::$config = $config;
}

if (!isset($config['driver'])) {
throw new MailException(
"The driver is not defined.",
E_USER_ERROR
);
}

if (!in_array($config['driver'], array_keys(static::$drivers))) {
throw new MailException("The type is not known.", E_USER_ERROR);
throw new MailException(
"The driver is not defined.",
E_USER_ERROR
);
}

$name = $config['driver'];
Expand Down
2 changes: 1 addition & 1 deletion src/Middleware/AuthMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class AuthMiddleware implements BaseMiddleware
* Handle an incoming request.
*
* @param Request $request
* @param Callable $next
* @param callable $next
* @param array $args
* @return Redirect
*/
Expand Down
10 changes: 7 additions & 3 deletions src/Middleware/CsrfMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class CsrfMiddleware implements BaseMiddleware
* Handle an incoming request.
*
* @param Request $request
* @param Callable $next
* @param callable $next
* @param array $args
* @throws
*/
Expand All @@ -33,14 +33,18 @@ public function process(Request $request, callable $next, array $args = []): mix

response()->status(401);

throw new TokenMismatch('Token Mismatch');
throw new TokenMismatch(
'The request csrf token mismatch'
);
}

if ($request->get('_token') == $request->session()->get('_token')) {
return $next($request);
}

throw new TokenMismatch('Token Mismatch');
throw new TokenMismatch(
'The request csrf token mismatch'
);
}

/**
Expand Down
1 change: 0 additions & 1 deletion src/Session/Driver/DatabaseDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Bow\Session\Driver;

use Bow\Support\Capsule;
use Bow\Database\QueryBuilder;
use Bow\Database\Database as DB;

Expand Down
2 changes: 1 addition & 1 deletion src/Session/Driver/FilesystemDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function destroy(string $session_id): bool
* @param int $maxlifetime
* @return bool
*/
public function gc(int $maxlifetime): int
public function gc(int $maxlifetime): bool
{
foreach (glob($this->save_path . "/*") as $file) {
if (filemtime($file) + $maxlifetime < $this->createTimestamp() && file_exists($file)) {
Expand Down
13 changes: 9 additions & 4 deletions src/Session/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,9 @@ private function initializeDriver(): void
$driver = $this->driver[$this->config['driver']] ?? null;

if (is_null($driver)) {
throw new SessionException('The driver ' . $this->config['driver'] . ' is not valid');
throw new SessionException(
'The driver ' . $this->config['driver'] . ' is not valid'
);
}

switch ($this->config['driver']) {
Expand All @@ -174,13 +176,16 @@ private function initializeDriver(): void
$handler = new $driver();
break;
default:
throw new SessionException('Cannot set the session driver');
break;
throw new SessionException(
'Cannot set the session driver'
);
}

// Set the session driver
if (!@session_set_save_handler($handler, true)) {
throw new SessionException('Cannot set the session driver');
throw new SessionException(
'Cannot set the session driver'
);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Storage/Service/DiskFilesystemService.php
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ public function copy(string $target, string $source): bool
}

if (!$this->exists($source)) {
$this->makeDirectory(dirname($source), true);
$this->makeDirectory(dirname($source));
}

return (bool) file_put_contents($source, $this->get($target));
Expand Down
6 changes: 3 additions & 3 deletions src/Storage/Service/FTPService.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ public function store(UploadFile $file, ?string $location = null, array $option
rewind($stream);

//
$result = $this->writeStream($location, $stream, $option);
$result = $this->writeStream($location, $stream);
fclose($stream);

if ($result === false) {
Expand Down Expand Up @@ -358,7 +358,7 @@ public function makeDirectory(string $dirname, int $mode = 0777): bool
$directories = explode('/', $dirname);

foreach ($directories as $directory) {
if (false === $this->makeActualDirectory($directory, $mode)) {
if (false === $this->makeActualDirectory($directory)) {
$this->setConnectionRoot();
return false;
}
Expand Down Expand Up @@ -405,7 +405,7 @@ protected function makeActualDirectory(string $directory): bool
public function get(string $filename): ?string
{
if (!$stream = $this->readStream($filename)) {
return false;
return null;
}

$contents = stream_get_contents($stream);
Expand Down
12 changes: 6 additions & 6 deletions src/Storage/Service/S3Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,22 +127,22 @@ public function prepend(string $filename, string $content): bool
* @param string $content
* @param array $options
*
* @return bool
* @return mixed
*/
public function put(string $file, string $content, array $options = []): bool
public function put(string $file, string $content, array $options = []): mixed
{
$options = is_string($options)
? ['visibility' => $options]
: (array) $options;

$this->client->putObject([
$result = $this->client->putObject([
'Bucket' => $this->config['bucket'],
'Key' => $file,
'Body' => $content,
"Visibility" => $options["visibility"] ?? 'public'
]);

return true;
return $result;
}

/**
Expand Down Expand Up @@ -221,9 +221,9 @@ public function makeDirectory(string $bucket, int $mode = 0777, array $option =
* Recover the contents of the file
*
* @param string $filename
* @return null|string
* @return ?string
*/
public function get(string $filename): string
public function get(string $filename): ?string
{
$result = $this->client->getObject([
'Bucket' => $this->config['bucket'],
Expand Down
4 changes: 3 additions & 1 deletion src/Storage/Storage.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,8 @@ public static function __callStatic($name, array $arguments)
return call_user_func_array([static::$disk, $name], $arguments);
}

throw new BadMethodCallException("unkdown $name method");
throw new BadMethodCallException(
"The method $name is not defined"
);
}
}
Loading

0 comments on commit 0e1b454

Please sign in to comment.