Skip to content

Commit

Permalink
Merge pull request #9 from dicoding-dev/feature/symfony-6
Browse files Browse the repository at this point in the history
Upgrade Symfony components to 6.x
  • Loading branch information
rizqyhi authored May 5, 2024
2 parents 8db410b + 1a36900 commit e1d1bcd
Show file tree
Hide file tree
Showing 63 changed files with 414 additions and 239 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pull-request-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ jobs:
- name: Running unit test
uses: php-actions/phpunit@v3
with:
version: 9.5
version: 9.6
php_version: 8.1
configuration: phpunit.xml
51 changes: 26 additions & 25 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,31 @@
"require": {
"php": ">=8.1.0",
"d11wtq/boris": "~1.0",
"filp/whoops": "~2.11",
"ircmaxell/password-compat": "~1.0",
"laravel/serializable-closure": "^1.2",
"monolog/monolog": "~1.6",
"nesbot/carbon": "~2.0",
"nesbot/carbon": "^2.71",
"opis/closure": "~3.6",
"pda/pheanstalk": "~4.0",
"phpseclib/phpseclib": "~2.0",
"predis/predis": "^1.1",
"stack/builder": "~1.0",
"swiftmailer/swiftmailer": "^6.0",
"symfony/browser-kit": "~4.4",
"symfony/console": "~4.4",
"symfony/css-selector": "~4.4",
"symfony/dom-crawler": "~4.4",
"symfony/finder": "~4.4",
"symfony/http-foundation": "~4.4",
"symfony/http-kernel": "~4.4",
"symfony/process": "~4.4",
"symfony/routing": "~4.4",
"symfony/security-core": "~4.4",
"symfony/translation": "~4.4",
"symfony/event-dispatcher": "~4.4",
"symfony/mime": "~5.0.0",
"symfony/error-handler": "~4.4",
"pda/pheanstalk": "~4.0",
"opis/closure": "~3.6",
"voku/portable-ascii": "~1.5",
"filp/whoops": "~2.11",
"laravel/serializable-closure": "^1.2"
"symfony/browser-kit": "~6.4",
"symfony/console": "~6.4",
"symfony/css-selector": "~6.4",
"symfony/dom-crawler": "~6.4",
"symfony/error-handler": "~6.4",
"symfony/event-dispatcher": "~6.4",
"symfony/finder": "~6.4",
"symfony/http-foundation": "~6.4",
"symfony/http-kernel": "~6.4",
"symfony/mime": "~6.4",
"symfony/process": "~6.4",
"symfony/routing": "~6.4",
"symfony/security-core": "~6.4",
"symfony/translation": "~6.4",
"voku/portable-ascii": "~1.5"
},
"replace": {
"illuminate/auth": "self.version",
Expand Down Expand Up @@ -71,10 +70,9 @@
},
"require-dev": {
"mockery/mockery": "~1.3",
"phpunit/phpunit": "~9.5",
"phpunit/phpunit": "~9.6",
"phpspec/prophecy-phpunit": "~2.0",
"symfony/debug": "~4.4",
"symfony/var-dumper": "~4.4"
"symfony/var-dumper": "~6.4"
},
"autoload": {
"classmap": [
Expand Down Expand Up @@ -104,5 +102,8 @@
"suggest": {
"doctrine/dbal": "Allow renaming columns and dropping SQLite columns."
},
"minimum-stability": "stable"
"minimum-stability": "stable",
"config": {
"sort-packages": true
}
}
4 changes: 4 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,8 @@
<directory suffix="Test.php">./tests</directory>
</testsuite>
</testsuites>
<php>
<ini name="display_errors" value="On" />
<ini name="display_startup_errors" value="On" />
</php>
</phpunit>
4 changes: 2 additions & 2 deletions src/Illuminate/Console/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@ public function resolveCommands($commands)
*
* @return \Symfony\Component\Console\Input\InputDefinition
*/
protected function getDefaultInputDefinition()
{
protected function getDefaultInputDefinition(): \Symfony\Component\Console\Input\InputDefinition
{
$definition = parent::getDefaultInputDefinition();

$definition->addOption($this->getEnvironmentOption());
Expand Down
15 changes: 9 additions & 6 deletions src/Illuminate/Console/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class Command extends \Symfony\Component\Console\Command\Command {
*
* @var string
*/
protected $description;
protected $description = '';

/**
* Create a new console command instance.
Expand Down Expand Up @@ -91,8 +91,8 @@ protected function specifyParameters()
* @param \Symfony\Component\Console\Output\OutputInterface $output
* @return int
*/
public function run(InputInterface $input, OutputInterface $output)
{
public function run(InputInterface $input, OutputInterface $output): int
{
$this->input = $input;

$this->output = $output;
Expand All @@ -107,9 +107,12 @@ public function run(InputInterface $input, OutputInterface $output)
* @param \Symfony\Component\Console\Output\OutputInterface $output
* @return mixed
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
return $this->fire();
protected function execute(InputInterface $input, OutputInterface $output): mixed
{
// Symfony 5 removed support of returning null, so we cast the returned value as integer.
// In this case, void-returned fire() method will be casted to 0.
// @see https://github.com/symfony/console/blob/6.3/CHANGELOG.md#500
return (int) $this->fire();
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Illuminate/Cookie/Guard.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ public function __construct(HttpKernelInterface $app, Encrypter $encrypter)
* @param bool $catch
* @return \Symfony\Component\HttpFoundation\Response
*/
public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = true)
{
public function handle(Request $request, $type = HttpKernelInterface::MAIN_REQUEST, $catch = true): Response
{
return $this->encrypt($this->app->handle($this->decrypt($request), $type, $catch));
}

Expand Down
4 changes: 2 additions & 2 deletions src/Illuminate/Cookie/Queue.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ public function __construct(HttpKernelInterface $app, CookieJar $cookies)
* @param bool $catch
* @return \Symfony\Component\HttpFoundation\Response
*/
public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = true)
{
public function handle(Request $request, $type = HttpKernelInterface::MAIN_REQUEST, $catch = true): \Symfony\Component\HttpFoundation\Response
{
$response = $this->app->handle($request, $type, $catch);

foreach ($this->cookies->getQueuedCookies() as $cookie)
Expand Down
6 changes: 4 additions & 2 deletions src/Illuminate/Database/Console/Migrations/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,17 @@ public function __construct(MigrationRepositoryInterface $repository)
/**
* Execute the console command.
*
* @return void
*/
* @return int
*/
public function fire()
{
$this->repository->setSource($this->input->getOption('database'));

$this->repository->createRepository();

$this->info("Migration table created successfully.");

return 0;
}

/**
Expand Down
6 changes: 4 additions & 2 deletions src/Illuminate/Database/Console/Migrations/MigrateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ public function __construct(Migrator $migrator, $packagePath)
/**
* Execute the console command.
*
* @return void
*/
* @return int
*/
public function fire()
{
if ( ! $this->confirmToProceed()) return;
Expand Down Expand Up @@ -84,6 +84,8 @@ public function fire()
{
$this->call('db:seed', ['--force' => true]);
}

return 0;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ public function __construct(MigrationCreator $creator, $packagePath)
/**
* Execute the console command.
*
* @return void
*/
* @return int
*/
public function fire()
{
// It's possible for the developer to specify the tables to modify in this
Expand All @@ -73,6 +73,8 @@ public function fire()
$this->writeMigration($name, $table, $create);

$this->call('dump-autoload');

return 0;
}

/**
Expand Down
6 changes: 4 additions & 2 deletions src/Illuminate/Database/Console/Migrations/RefreshCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ class RefreshCommand extends Command {
/**
* Execute the console command.
*
* @return void
*/
* @return int
*/
public function fire()
{
if ( ! $this->confirmToProceed()) return;
Expand All @@ -50,6 +50,8 @@ public function fire()
{
$this->runSeeder($database);
}

return 0;
}

/**
Expand Down
6 changes: 4 additions & 2 deletions src/Illuminate/Database/Console/Migrations/ResetCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ public function __construct(Migrator $migrator)
/**
* Execute the console command.
*
* @return void
*/
* @return int
*/
public function fire()
{
if ( ! $this->confirmToProceed()) return;
Expand All @@ -70,6 +70,8 @@ public function fire()

if ($count == 0) break;
}

return 0;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ public function __construct(Migrator $migrator)
/**
* Execute the console command.
*
* @return void
*/
* @return int
*/
public function fire()
{
if ( ! $this->confirmToProceed()) return;
Expand All @@ -65,6 +65,8 @@ public function fire()
{
$this->output->writeln($note);
}

return 0;
}

/**
Expand Down
6 changes: 4 additions & 2 deletions src/Illuminate/Database/Console/SeedCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,17 @@ public function __construct(Resolver $resolver)
/**
* Execute the console command.
*
* @return void
*/
* @return int
*/
public function fire()
{
if ( ! $this->confirmToProceed()) return;

$this->resolver->setDefaultConnection($this->getDatabase());

$this->getSeeder()->run();

return 0;
}

/**
Expand Down
25 changes: 18 additions & 7 deletions src/Illuminate/Exception/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
use Closure;
use ErrorException;
use ReflectionFunction;
use Symfony\Component\Debug\Exception\FatalThrowableError;
use Illuminate\Support\Contracts\ResponsePreparerInterface;
use Symfony\Component\ErrorHandler\Error\FatalError;
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
use Symfony\Component\Debug\Exception\FatalErrorException as FatalError;

class Handler {

Expand Down Expand Up @@ -188,11 +187,9 @@ public function handleShutdown()
// code so it can be displayed back out to the developer for information.
if ( ! is_null($error))
{
extract($error);
if ( ! $this->isFatal($error['type'])) return;

if ( ! $this->isFatal($type)) return;

$this->handleException(new FatalError($message, $type, 0, $file, $line))->send();
$this->handleException(new FatalError($error['message'], 0, $error, 0))->send();
}
}

Expand Down Expand Up @@ -272,7 +269,21 @@ protected function displayException($exception)
$displayer = $this->debug ? $this->debugDisplayer : $this->plainDisplayer;

if (! $exception instanceof \Exception) {
$exception = new FatalThrowableError($exception);
if ($exception instanceof \ParseError) {
$severity = \E_PARSE;
} elseif ($exception instanceof \TypeError) {
$severity = \E_RECOVERABLE_ERROR;
} else {
$severity = \E_ERROR;
}

$exception = new ErrorException(
$exception->getMessage(),
$exception->getCode(),
$severity,
$exception->getFile(),
$exception->getLine(),
);
}

return $displayer->display($exception);
Expand Down
Loading

0 comments on commit e1d1bcd

Please sign in to comment.