Skip to content

Commit

Permalink
refactor: optimisation of codebase
Browse files Browse the repository at this point in the history
  • Loading branch information
papac committed Jan 26, 2025
1 parent 1b8eb52 commit 82687ee
Show file tree
Hide file tree
Showing 30 changed files with 68 additions and 73 deletions.
2 changes: 1 addition & 1 deletion src/Auth/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Bow Framework auth is a native authentification system
```php
use Bow\Http\Exception\UnauthorizedException;

$auth = auth();
$auth = app_auth();

$logged = $auth->attempts(["username" => "[email protected]", "password" => "password"]);

Expand Down
7 changes: 4 additions & 3 deletions src/Database/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Bow\Database\Exception\ConnectionException;
use Bow\Database\Exception\DatabaseException;
use Bow\Security\Sanitize;
use ErrorException;
use PDO;

class Database
Expand All @@ -25,7 +26,7 @@ class Database
/**
* The singleton Database instance
*
* @var Database
* @var ?Database
*/
private static ?Database $instance = null;

Expand All @@ -39,7 +40,7 @@ class Database
/**
* Configuration
*
* @var string
* @var ?string
*/
private static ?string $name = null;

Expand Down Expand Up @@ -330,7 +331,7 @@ public static function statement(string $sql_statement): bool
/**
* Execute a delete request
*
* @param $sql_statement
* @param string $sql_statement
* @param array $data
* @return int
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Mail/Driver/NativeDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
namespace Bow\Mail\Driver;

use Bow\Mail\Contracts\MailDriverInterface;
use Bow\Mail\Exception\MailException;
use Bow\Mail\Envelop;
use Bow\Mail\Exception\MailException;
use InvalidArgumentException;

class NativeDriver implements MailDriverInterface
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 @@ -5,13 +5,13 @@
namespace Bow\Mail\Driver;

use Bow\Mail\Contracts\MailDriverInterface;
use Bow\Mail\Envelop;
use Bow\Mail\Exception\MailException;
use Bow\Mail\Exception\SmtpException;
use Bow\Mail\Exception\SocketException;
use Bow\Mail\Envelop;
use ErrorException;
use Bow\Mail\Security\DkimSigner;
use Bow\Mail\Security\SpfChecker;
use Bow\Mail\Exception\MailException;
use ErrorException;

class SmtpDriver implements MailDriverInterface
{
Expand Down
9 changes: 2 additions & 7 deletions src/Messaging/Channel/DatabaseChannel.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,13 @@

namespace Bow\Messaging\Channel;

use Bow\Database\Database;
use Bow\Messaging\Messaging;
use Bow\Database\Barry\Model;
use Bow\Database\Database;
use Bow\Messaging\Contracts\ChannelInterface;
use Bow\Messaging\Messaging;

class DatabaseChannel implements ChannelInterface
{
public function __construct(
private readonly array $database
) {
}

/**
* Send the notification to database
*
Expand Down
5 changes: 2 additions & 3 deletions src/Messaging/Channel/MailChannel.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@

namespace Bow\Messaging\Channel;

use Bow\Mail\Mail;
use Bow\Mail\Envelop;
use Bow\Messaging\Messaging;
use Bow\Database\Barry\Model;
use Bow\Mail\Mail;
use Bow\Messaging\Contracts\ChannelInterface;
use Bow\Messaging\Messaging;

class MailChannel implements ChannelInterface
{
Expand Down
6 changes: 4 additions & 2 deletions src/Messaging/Channel/SlackChannel.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

namespace Bow\Messaging\Channel;

use GuzzleHttp\Client;
use Bow\Messaging\Messaging;
use Bow\Database\Barry\Model;
use Bow\Messaging\Contracts\ChannelInterface;
use Bow\Messaging\Messaging;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\GuzzleException;

class SlackChannel implements ChannelInterface
{
Expand All @@ -15,6 +16,7 @@ class SlackChannel implements ChannelInterface
* @param Model $context
* @param Messaging $message
* @return void
* @throws GuzzleException
*/
public function send(Model $context, Messaging $message): void
{
Expand Down
14 changes: 8 additions & 6 deletions src/Messaging/Channel/SmsChannel.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

namespace Bow\Messaging\Channel;

use Twilio\Rest\Client;
use Bow\Messaging\Messaging;
use Bow\Database\Barry\Model;
use Bow\Messaging\Contracts\ChannelInterface;
use Bow\Messaging\Messaging;
use InvalidArgumentException;
use Twilio\Exceptions\ConfigurationException;
use Twilio\Rest\Client;

class SmsChannel implements ChannelInterface
{
Expand All @@ -22,7 +24,7 @@ class SmsChannel implements ChannelInterface
/**
* Constructor
*
* @throws \InvalidArgumentException When Twilio credentials are missing
* @throws InvalidArgumentException|ConfigurationException When Twilio credentials are missing
*/
public function __construct()
{
Expand All @@ -31,7 +33,7 @@ public function __construct()
$this->from_number = config('messaging.twilio.from');

if (!$account_sid || !$auth_token || !$this->from_number) {
throw new \InvalidArgumentException('Twilio credentials are required');
throw new InvalidArgumentException('Twilio credentials are required');
}

$this->client = new Client($account_sid, $auth_token);
Expand Down Expand Up @@ -69,13 +71,13 @@ private function sendWithTwilio(Model $context, Messaging $message): void
$this->from_number = config('messaging.twilio.from');

if (!$account_sid || !$auth_token || !$this->from_number) {
throw new \InvalidArgumentException('Twilio credentials are required');
throw new InvalidArgumentException('Twilio credentials are required');
}

$this->client = new Client($account_sid, $auth_token);

if (!isset($data['to']) || !isset($data['message'])) {
throw new \InvalidArgumentException('The phone number and message are required');
throw new InvalidArgumentException('The phone number and message are required');
}

try {
Expand Down
19 changes: 12 additions & 7 deletions src/Messaging/Channel/TelegramChannel.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@

namespace Bow\Messaging\Channel;

use GuzzleHttp\Client;
use Bow\Messaging\Messaging;
use Bow\Database\Barry\Model;
use Bow\Messaging\Contracts\ChannelInterface;
use Bow\Messaging\Messaging;
use Exception;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\GuzzleException;
use InvalidArgumentException;
use RuntimeException;

class TelegramChannel implements ChannelInterface
{
Expand All @@ -17,14 +21,14 @@ class TelegramChannel implements ChannelInterface
/**
* Constructor
*
* @throws \InvalidArgumentException When Telegram bot token is missing
* @throws InvalidArgumentException When Telegram bot token is missing
*/
public function __construct()
{
$this->botToken = config('messaging.telegram.bot_token');

if (!$this->botToken) {
throw new \InvalidArgumentException('The Telegram bot token is required');
throw new InvalidArgumentException('The Telegram bot token is required');
}
}

Expand All @@ -34,6 +38,7 @@ public function __construct()
* @param Model $context
* @param Messaging $message
* @return void
* @throws GuzzleException
*/
public function send(Model $context, Messaging $message): void
{
Expand All @@ -44,7 +49,7 @@ public function send(Model $context, Messaging $message): void
$data = $message->toTelegram($context);

if (!isset($data['chat_id']) || !isset($data['message'])) {
throw new \InvalidArgumentException('The chat ID and message are required for Telegram');
throw new InvalidArgumentException('The chat ID and message are required for Telegram');
}

$client = new Client();
Expand All @@ -58,8 +63,8 @@ public function send(Model $context, Messaging $message): void
'parse_mode' => $data['parse_mode'] ?? 'HTML'
]
]);
} catch (\Exception $e) {
throw new \RuntimeException('Error while sending Telegram message: ' . $e->getMessage());
} catch (Exception $e) {
throw new RuntimeException('Error while sending Telegram message: ' . $e->getMessage());
}
}
}
2 changes: 1 addition & 1 deletion src/Messaging/Contracts/ChannelInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace Bow\Messaging\Contracts;

use Bow\Messaging\Messaging;
use Bow\Database\Barry\Model;
use Bow\Messaging\Messaging;

interface ChannelInterface
{
Expand Down
6 changes: 3 additions & 3 deletions src/Messaging/Messaging.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

namespace Bow\Messaging;

use Bow\Mail\Envelop;
use Bow\Database\Barry\Model;
use Bow\Messaging\Channel\SmsChannel;
use Bow\Mail\Envelop;
use Bow\Messaging\Channel\DatabaseChannel;
use Bow\Messaging\Channel\MailChannel;
use Bow\Messaging\Channel\SlackChannel;
use Bow\Messaging\Channel\DatabaseChannel;
use Bow\Messaging\Channel\SmsChannel;
use Bow\Messaging\Channel\TelegramChannel;

abstract class Messaging
Expand Down
8 changes: 4 additions & 4 deletions tests/Application/ApplicationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

namespace Bow\Tests\Application;

use Mockery;
use Bow\Application\Application;
use Bow\Container\Capsule;
use Bow\Http\Request;
use Bow\Http\Response;
use Bow\Container\Capsule;
use Bow\Application\Application;
use Bow\Testing\KernelTesting;
use Bow\Router\Exception\RouterException;
use Bow\Testing\KernelTesting;
use Bow\Tests\Config\TestingConfiguration;
use Mockery;

class ApplicationTest extends \PHPUnit\Framework\TestCase
{
Expand Down
10 changes: 5 additions & 5 deletions tests/Auth/AuthenticationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
namespace Bow\Tests\Auth;

use Bow\Auth\Auth;
use Bow\Security\Hash;
use Policier\Policier;
use Bow\Database\Database;
use Bow\Auth\Authentication;
use Bow\Auth\Exception\AuthenticationException;
use Bow\Auth\Guards\GuardContract;
use Bow\Auth\Guards\JwtGuard;
use Bow\Auth\Guards\SessionGuard;
use Bow\Auth\Guards\GuardContract;
use Bow\Database\Database;
use Bow\Security\Hash;
use Bow\Tests\Auth\Stubs\UserModelStub;
use Bow\Tests\Config\TestingConfiguration;
use Bow\Auth\Exception\AuthenticationException;
use Policier\Policier;

class AuthenticationTest extends \PHPUnit\Framework\TestCase
{
Expand Down
1 change: 0 additions & 1 deletion tests/Console/CustomCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Bow\Console\Console;
use Bow\Console\Setting;
use Bow\Tests\Console\Stubs\CustomCommand;

class CustomCommandTest extends \PHPUnit\Framework\TestCase
{
Expand Down
2 changes: 1 addition & 1 deletion tests/Container/CapsuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace Bow\Tests\Container;

use StdClass;
use Bow\Container\Capsule;
use Bow\Tests\Container\Stubs\MyClass;
use StdClass;

class CapsuleTest extends \PHPUnit\Framework\TestCase
{
Expand Down
6 changes: 3 additions & 3 deletions tests/Database/ConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

namespace Bow\Tests\Database;

use Bow\Tests\Config\TestingConfiguration;
use Bow\Configuration\Loader as ConfigurationLoader;
use Bow\Database\Connection\AbstractConnection;
use Bow\Database\Connection\Adapter\MysqlAdapter;
use Bow\Database\Connection\Adapter\SqliteAdapter;
use Bow\Configuration\Loader as ConfigurationLoader;
use Bow\Database\Connection\Adapter\PostgreSQLAdapter;
use Bow\Database\Connection\Adapter\SqliteAdapter;
use Bow\Tests\Config\TestingConfiguration;

class ConnectionTest extends \PHPUnit\Framework\TestCase
{
Expand Down
2 changes: 1 addition & 1 deletion tests/Database/PaginationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

namespace Tests\Bow\Database;

use PHPUnit\Framework\TestCase;
use Bow\Database\Pagination;
use PHPUnit\Framework\TestCase;

class PaginationTest extends TestCase
{
Expand Down
4 changes: 2 additions & 2 deletions tests/Database/Relation/BelongsToRelationQueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
use Bow\Database\Database;
use Bow\Database\Migration\SQLGenerator;
use Bow\Tests\Config\TestingConfiguration;
use Bow\Tests\Database\Stubs\PetModelStub;
use Bow\Tests\Database\Stubs\PetMasterModelStub;
use Bow\Tests\Database\Stubs\MigrationExtendedStub;
use Bow\Tests\Database\Stubs\PetMasterModelStub;
use Bow\Tests\Database\Stubs\PetModelStub;

class BelongsToRelationQueryTest extends \PHPUnit\Framework\TestCase
{
Expand Down
1 change: 0 additions & 1 deletion tests/Database/Stubs/PetMasterModelStub.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Bow\Tests\Database\Stubs;

use Bow\Database\Barry\Relations\HasMany;
use Bow\Tests\Database\Stubs\PetModelStub;

class PetMasterModelStub extends \Bow\Database\Barry\Model
{
Expand Down
1 change: 0 additions & 1 deletion tests/Database/Stubs/PetWithMasterModelStub.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Bow\Tests\Database\Stubs;

use Bow\Database\Barry\Relations\BelongsTo;
use Bow\Tests\Database\Stubs\PetMasterModelStub;

class PetWithMasterModelStub extends \Bow\Database\Barry\Model
{
Expand Down
6 changes: 3 additions & 3 deletions tests/Events/EventTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

namespace Bow\Tests\Events;

use Bow\Event\Event;
use Bow\Database\Database;
use Bow\Event\Event;
use Bow\Tests\Config\TestingConfiguration;
use PHPUnit\Framework\Assert;
use Bow\Tests\Events\Stubs\EventModelStub;
use Bow\Tests\Events\Stubs\UserEventStub;
use Bow\Tests\Events\Stubs\UserEventListenerStub;
use Bow\Tests\Events\Stubs\UserEventStub;
use PHPUnit\Framework\Assert;

class EventTest extends \PHPUnit\Framework\TestCase
{
Expand Down
Loading

0 comments on commit 82687ee

Please sign in to comment.