Skip to content

Commit

Permalink
Run CS Fixer
Browse files Browse the repository at this point in the history
  • Loading branch information
usernane committed Jan 16, 2024
1 parent 2bc30bc commit 66ba339
Show file tree
Hide file tree
Showing 21 changed files with 611 additions and 593 deletions.
13 changes: 7 additions & 6 deletions ecs.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
use Symplify\EasyCodingStandard\Config\ECSConfig;
use Symplify\EasyCodingStandard\ValueObject\Set\SetList;

return function (ECSConfig $ecsConfig): void {
return function (ECSConfig $ecsConfig): void
{
$ecsConfig->paths([
__DIR__ . '/app',
__DIR__ . '/public',
__DIR__ . '/tests',
__DIR__ . '/themes',
__DIR__ . '/webfiori',
__DIR__.'/app',
__DIR__.'/public',
__DIR__.'/tests',
__DIR__.'/themes',
__DIR__.'/webfiori',
]);

// this way you add a single rule
Expand Down
5 changes: 3 additions & 2 deletions tests/webfiori/framework/test/cli/CreateTableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,7 @@ public function testCreateTable05() {
$this->assertEquals(DataType::INT, $idCol->getDatatype());
$this->assertTrue($idCol->isPrimary());
$this->assertTrue($idCol->isUnique());

return $clazz;
}
/**
Expand Down Expand Up @@ -546,7 +547,7 @@ public function testCreateTable06($refTable) {
$output = $runner->getOutput();
$clazz = '\\app\\database\\Cool06Table';
$this->assertTrue(class_exists($clazz));

$this->removeClass($clazz);
$this->assertEquals(array_merge([
"Database type:\n",
Expand Down Expand Up @@ -597,7 +598,7 @@ public function testCreateTable06($refTable) {
"Would you like to create an entity class that maps to the database table?(y/N)\n",
'Info: New class was created at "'.ROOT_PATH.DS.'app'.DS."database\".\n",
]), $output);

$instance = new $clazz();
$instance instanceof Table;
$this->assertEquals(1, $instance->getForeignKeysCount());
Expand Down
7 changes: 3 additions & 4 deletions tests/webfiori/framework/test/cli/RunSQLCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ public function testCLIQuery01() {
* @test
*/
public function testCLIQuery02() {

JsonDriver::setConfigFileName('run-sql-test');
App::setConfigDriver(JsonDriver::class);

Expand All @@ -97,11 +96,11 @@ public function testCLIQuery02() {
App::getConfig()->addOrUpdateDBConnection($conn);
$driver = new JsonDriver();
$driver->setConfigFileName('run-sql-test');

Controller::setDriver($driver);

$this->assertTrue(get_class(App::getConfig()) == JsonDriver::class);

$runner = App::getRunner();
$runner->setArgsVector([
'webfiori',
Expand Down
1 change: 1 addition & 0 deletions tests/webfiori/framework/test/cli/SchedulerCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ public function test05() {
"Skip"];
$actual = $runner->getOutput();
$idx = 0;

foreach ($expected as $item) {
if ($item == 'Skip') {
break;
Expand Down
84 changes: 42 additions & 42 deletions tests/webfiori/framework/test/router/RouterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ public function test00() {
*/
public function testAddAPIRoute00() {
$this->assertTrue(Router::api([
RouteOption::PATH => '/call-api-00',
RouteOption::TO => '/my-api.php']));
RouteOption::PATH => '/call-api-00',
RouteOption::TO => '/my-api.php']));
$this->assertFalse(Router::page([
RouteOption::PATH => '/call-api-00',
RouteOption::TO => '/my-other-api.php']));
RouteOption::PATH => '/call-api-00',
RouteOption::TO => '/my-other-api.php']));
$this->assertTrue(Router::page([
RouteOption::PATH => '/call-api-01',
RouteOption::PATH => '/call-api-01',
RouteOption::TO => '/my-api.php']));
}
/**
Expand All @@ -45,35 +45,35 @@ public function testAddClosureRoute00() {
{
};
$this->assertTrue(Router::closure([
RouteOption::PATH => '/call',
RouteOption::TO => $c1
RouteOption::PATH => '/call',
RouteOption::TO => $c1
]));
$this->assertFalse(Router::closure([
RouteOption::PATH => '/call',
RouteOption::TO => $c2
RouteOption::PATH => '/call',
RouteOption::TO => $c2
]));
$this->assertTrue(Router::closure([
RouteOption::PATH => '/call-2',
RouteOption::TO => $c1
RouteOption::PATH => '/call-2',
RouteOption::TO => $c1
]));
$this->assertFalse(Router::closure([
RouteOption::PATH => '/call',
RouteOption::TO => 'Not Func'
RouteOption::PATH => '/call',
RouteOption::TO => 'Not Func'
]));
}
/**
* @test
*/
public function testAddViewRoute00() {
$this->assertTrue(Router::page([
RouteOption::PATH => '/view-something',
RouteOption::TO => 'my-view.php']));
RouteOption::PATH => '/view-something',
RouteOption::TO => 'my-view.php']));
$this->assertFalse(Router::page([
RouteOption::PATH => '/view-something',
RouteOption::TO => '/my-other-view.php']));
RouteOption::PATH => '/view-something',
RouteOption::TO => '/my-other-view.php']));
$this->assertTrue(Router::page([
RouteOption::PATH => '/view-something-2',
RouteOption::TO => '/my-view.php']));
RouteOption::PATH => '/view-something-2',
RouteOption::TO => '/my-view.php']));
}
/**
* @test
Expand All @@ -84,8 +84,8 @@ public function testOptionalParam00() {
{
});
Router::closure([
RouteOption::PATH => '{var-1}/{var-2?}',
RouteOption::TO => function()
RouteOption::PATH => '{var-1}/{var-2?}',
RouteOption::TO => function()
{
},
RouteOption::VALUES => [
Expand All @@ -110,8 +110,8 @@ public function testOptionalParam01() {
Router::removeAll();

Router::closure([
RouteOption::PATH => '{var-1}/{var-2?}',
RouteOption::TO => function()
RouteOption::PATH => '{var-1}/{var-2?}',
RouteOption::TO => function()
{
}
]);
Expand All @@ -132,8 +132,8 @@ public function testRoute00() {
{
});
Router::closure([
RouteOption::PATH => '{var-1}/{var-2}',
RouteOption::TO => function()
RouteOption::PATH => '{var-1}/{var-2}',
RouteOption::TO => function()
{
}
]);
Expand All @@ -155,8 +155,8 @@ public function testRoute01() {
{
});
Router::closure([
RouteOption::PATH => '{var-1}/{var-2}/{var-1}',
RouteOption::TO => function()
RouteOption::PATH => '{var-1}/{var-2}/{var-1}',
RouteOption::TO => function()
{
}
]);
Expand All @@ -172,37 +172,37 @@ public function testRoute01() {
public function testRoutesGroup00() {
Router::removeAll();
Router::page([
RouteOption::PATH => 'users',
RouteOption::PATH => 'users',
RouteOption::CASE_SENSITIVE => false,
RouteOption::MIDDLEWARE => 'M1',
RouteOption::LANGS => ['EN'],
RouteOption::REQUEST_METHODS => RequestMethod::POST,
RouteOption::SUB_ROUTES => [
RouteOption::SUB_ROUTES => [
[
RouteOption::PATH => 'view-user/{user-id}',
RouteOption::TO => 'ViewUserPage.php',
RouteOption::LANGS => ['AR']
RouteOption::PATH => 'view-user/{user-id}',
RouteOption::TO => 'ViewUserPage.php',
RouteOption::LANGS => ['AR']
],
[
RouteOption::PATH => 'get-users',
RouteOption::LANGS => ['AR'],
RouteOption::PATH => 'get-users',
RouteOption::LANGS => ['AR'],
RouteOption::CASE_SENSITIVE => true,
RouteOption::SUB_ROUTES => [
RouteOption::SUB_ROUTES => [
[
RouteOption::PATH => 'by-name',
RouteOption::TO => 'GetUserByName.php',
RouteOption::LANGS => ['FR'],
RouteOption::PATH => 'by-name',
RouteOption::TO => 'GetUserByName.php',
RouteOption::LANGS => ['FR'],
RouteOption::CASE_SENSITIVE => false,
],
[
RouteOption::PATH => 'by-email',
RouteOption::TO => 'GetUserByEmail.php'
RouteOption::PATH => 'by-email',
RouteOption::TO => 'GetUserByEmail.php'
]
],
],
[
RouteOption::PATH => '/',
RouteOption::TO => 'ListUsers.php',
RouteOption::PATH => '/',
RouteOption::TO => 'ListUsers.php',
RouteOption::CASE_SENSITIVE => true,
RouteOption::REQUEST_METHODS => [RequestMethod::OPTIONS, RequestMethod::GET]
]
Expand Down
58 changes: 30 additions & 28 deletions webfiori/framework/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,31 +45,6 @@
*
*/
class App {
/**
* Sets the class that will be used as configuration driver.
*
* This method must be used before calling the method 'App::start()' in order
* to set proper configuration driver.
*
* @param string $clazz The full name of the class including namespace.
*/
public static function setConfigDriver(string $clazz) {
self::$ConfigDriver = $clazz;
}
/**
* Returns the class that represents configuration driver.
*
* @return string The full name of the class including namespace.
*/
public static function getConfigDriver() : string {
return self::$ConfigDriver;
}
/**
* A string which points to the class that represents configuration driver.
*
* @var string
*/
private static $ConfigDriver = 'webfiori\\framework\\config\\ClassDriver';
/**
* A constant that indicates that the status of the class is 'initialized'.
*
Expand Down Expand Up @@ -106,6 +81,12 @@ public static function getConfigDriver() : string {
* @var Runner
*/
private static $CliRunner;
/**
* A string which points to the class that represents configuration driver.
*
* @var string
*/
private static $ConfigDriver = 'webfiori\\framework\\config\\ClassDriver';
/**
* A single instance of the class.
*
Expand Down Expand Up @@ -295,14 +276,23 @@ public static function getClassStatus() {
*/
public static function getConfig(): ConfigurationDriver {
$driver = Controller::getDriver();

if (get_class($driver) != self::$ConfigDriver) {
Controller::setDriver(new self::$ConfigDriver());
Controller::get()->updateEnv();
$driver = Controller::getDriver();
}

return $driver;
}
/**
* Returns the class that represents configuration driver.
*
* @return string The full name of the class including namespace.
*/
public static function getConfigDriver() : string {
return self::$ConfigDriver;
}

/**
* Returns an instance which represents the class that is used to run the
Expand Down Expand Up @@ -368,6 +358,17 @@ public static function getRunner() : Runner {

return self::$CliRunner;
}
/**
* Sets the class that will be used as configuration driver.
*
* This method must be used before calling the method 'App::start()' in order
* to set proper configuration driver.
*
* @param string $clazz The full name of the class including namespace.
*/
public static function setConfigDriver(string $clazz) {
self::$ConfigDriver = $clazz;
}

/**
* Start your WebFiori application.
Expand Down Expand Up @@ -420,7 +421,7 @@ private function checkAppDir() {
/**
* Directory separator.
*/
define('DS', DIRECTORY_SEPARATOR);
define('DS', DIRECTORY_SEPARATOR);
}

if (!defined('APP_DIR')) {
Expand All @@ -437,13 +438,14 @@ private function checkAppDir() {
http_response_code(500);
die('Error: Unable to initialize the application. Invalid application directory name: "'.APP_DIR.'".');
}

if (!defined('APP_PATH')) {
/**
* The absolute path to application directory.
*
* @var string
*/
define('APP_PATH', ROOT_PATH.DIRECTORY_SEPARATOR.APP_DIR.DIRECTORY_SEPARATOR);
define('APP_PATH', ROOT_PATH.DIRECTORY_SEPARATOR.APP_DIR.DIRECTORY_SEPARATOR);
}
}

Expand Down
2 changes: 1 addition & 1 deletion webfiori/framework/DB.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function __construct($connName) {
}

if (!($conn instanceof ConnectionInfo)) {
throw new DatabaseException("No connection was found which has the name '$connName'. Driver: ". get_class(App::getConfig()).'.');
throw new DatabaseException("No connection was found which has the name '$connName'. Driver: ".get_class(App::getConfig()).'.');
}
}
parent::__construct($conn);
Expand Down
5 changes: 2 additions & 3 deletions webfiori/framework/EmailMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
*/
namespace webfiori\framework;

use webfiori\email\Email;
use webfiori\email\exceptions\SMTPException;
use webfiori\email\SMTPAccount;
use webfiori\framework\exceptions\MissingLangException;
use webfiori\email\Email;
/**
* A class that can be used to write HTML formatted Email messages.
*
Expand Down Expand Up @@ -82,13 +82,12 @@ public function getTranslation() {
*
* @return Email The method will return same instance at which the method is
* called on.
*
*
* @throws MissingLangException
*/
public function setLang(string $lang = 'EN') : Email {
if (parent::setLang($lang)) {
$this->usingLanguage();

}

return $this;
Expand Down
Loading

0 comments on commit 66ba339

Please sign in to comment.