Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Php code cleanup #119

Merged
merged 8 commits into from
Nov 13, 2023
Merged

Php code cleanup #119

merged 8 commits into from
Nov 13, 2023

Conversation

greylabel
Copy link
Contributor

@greylabel greylabel commented Nov 13, 2023

First of a couple PRs related to cleanup/modernizing before bumping to twig 3, and then update all the JS packages and implementation.

  • Start of adding types to PHP code
  • Various code styles cleanups and renaming
  • Make use of PHP 8.2 features

@@ -1,8 +1,10 @@
<?php

// declare(strict_types=1);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will enable this for all files in an upcoming PR.

use Twig\Environment;
use Twig\TwigFunction;

function addCustomExtension(Environment &$env, $config) {
$env->addFunction(new TwigFunction('customTwigFunctionThatSaysWorld', fn() => 'Custom World'));
function addCustomExtension(Environment &$twigEnvironment, $config): void {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes in this PR make use of new arrow function syntax and typing.


function __construct(array $config) {
$this->config = $config;
function __construct(public array $config) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$config makes use of new constructor promotion feature.

@@ -34,7 +36,7 @@
}

try {
$config = json_decode($configString, true);
$config = json_decode($configString, true, 512, JSON_THROW_ON_ERROR);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New JSON_THROW_ON_ERROR is a better error experience with json_decode and json_encode

@EvanLovely EvanLovely merged commit 4792fad into master Nov 13, 2023
4 checks passed
@EvanLovely EvanLovely deleted the php-code-cleanup branch November 13, 2023 22:57
Copy link

🚀 PR was released in v2.2.1 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants