Skip to content

Commit

Permalink
Fix CS
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed Dec 10, 2023
1 parent 54d34b9 commit aa7c454
Show file tree
Hide file tree
Showing 13 changed files with 30 additions and 24 deletions.
2 changes: 1 addition & 1 deletion extra/cssinliner-extra/CssInlinerExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public static function inlineCss(string $body, string ...$css): string
if (null === $inliner) {
$inliner = new CssToInlineStyles();
}

return $inliner->convert($body, implode("\n", $css));
}
}
1 change: 1 addition & 0 deletions extra/cssinliner-extra/Resources/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

/**
* @internal
*
* @deprecated since Twig 3.9.0
*/
function twig_inline_css(string $body, string ...$css): string
Expand Down
1 change: 1 addition & 0 deletions extra/cssinliner-extra/Tests/LegacyFunctionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use PHPUnit\Framework\TestCase;
use Twig\Extra\CssInliner\CssInlinerExtension;

use function Twig\Extra\CssInliner\twig_inline_css;

/**
Expand Down
1 change: 1 addition & 0 deletions extra/html-extra/Resources/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

/**
* @internal
*
* @deprecated since Twig 3.9.0
*/
function twig_html_classes(...$args): string
Expand Down
1 change: 1 addition & 0 deletions extra/inky-extra/Resources/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

/**
* @internal
*
* @deprecated since Twig 3.9.0
*/
function twig_inky(string $body): string
Expand Down
1 change: 1 addition & 0 deletions extra/inky-extra/Tests/LegacyFunctionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use PHPUnit\Framework\TestCase;
use Twig\Extra\Inky\InkyExtension;

use function Twig\Extra\Inky\twig_inky;

/**
Expand Down
8 changes: 4 additions & 4 deletions extra/markdown-extra/MarkdownExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,21 @@ public function getFilters()
public static function htmlToMarkdown(string $body, array $options = []): string
{
static $converters;

if (!class_exists(HtmlConverter::class)) {
throw new \LogicException('You cannot use the "html_to_markdown" filter as league/html-to-markdown is not installed; try running "composer require league/html-to-markdown".');
}

$options += [
'hard_break' => true,
'strip_tags' => true,
'remove_nodes' => 'head style',
];

if (!isset($converters[$key = serialize($options)])) {
$converters[$key] = new HtmlConverter($options);
}

return $converters[$key]->convert($body);
}
}
1 change: 1 addition & 0 deletions extra/markdown-extra/Resources/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

/**
* @internal
*
* @deprecated since Twig 3.9.0
*/
function html_to_markdown(string $body, array $options = []): string
Expand Down
4 changes: 3 additions & 1 deletion extra/markdown-extra/Tests/LegacyFunctionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@
namespace Twig\Extra\Markdown\Tests;

use PHPUnit\Framework\TestCase;
use Twig\Extra\Markdown\MarkdownExtension;

use function Twig\Extra\Markdown\html_to_markdown;

use Twig\Extra\Markdown\MarkdownExtension;

/**
* @group legacy
*/
Expand Down
3 changes: 1 addition & 2 deletions src/Extension/CoreExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,6 @@ public static function arrayMerge(...$arrays)
return $result;
}


/**
* Slices a variable.
*
Expand Down Expand Up @@ -1215,7 +1214,7 @@ public static function lowerFilter(Environment $env, $string)
/**
* Strips HTML and PHP tags from a string.
*
* @param string|null $string
* @param string|null $string
* @param string[]|string|null $string
*
* @return string
Expand Down
10 changes: 5 additions & 5 deletions src/Extension/DebugExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
namespace Twig\Extension;

use Twig\Environment;
use Twig\TwigFunction;
use Twig\Template;
use Twig\TemplateWrapper;
use Twig\TwigFunction;

final class DebugExtension extends AbstractExtension
{
Expand Down Expand Up @@ -43,22 +43,22 @@ public static function dump(Environment $env, $context, ...$vars)
if (!$env->isDebug()) {
return;
}

ob_start();

if (!$vars) {
$vars = [];
foreach ($context as $key => $value) {
if (!$value instanceof Template && !$value instanceof TemplateWrapper) {
$vars[$key] = $value;
}
}

var_dump($vars);
} else {
var_dump(...$vars);
}

return ob_get_clean();
}
}
19 changes: 9 additions & 10 deletions src/Extension/EscaperExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
use Twig\TokenParser\AutoEscapeTokenParser;
use Twig\TwigFilter;


final class EscaperExtension extends AbstractExtension
{
private $defaultStrategy;
Expand Down Expand Up @@ -177,7 +176,7 @@ public static function escapeFilterIsSafe(Node $filterArgs)
* @param bool $autoescape Whether the function is called by the auto-escaping feature (true) or by the developer (false)
*
* @return string
*
*
* @internal
*/
public static function escape(Environment $env, $string, $strategy = 'html', $charset = null, $autoescape = false)
Expand All @@ -190,7 +189,7 @@ public static function escape(Environment $env, $string, $strategy = 'html', $ch
if (\is_object($string) && method_exists($string, '__toString')) {
if ($autoescape) {
$c = \get_class($string);
$ext = $env->getExtension(EscaperExtension::class);
$ext = $env->getExtension(self::class);
if (!isset($ext->safeClasses[$c])) {
$ext->safeClasses[$c] = [];
foreach (class_parents($string) + class_implements($string) as $class) {
Expand Down Expand Up @@ -256,7 +255,7 @@ public static function escape(Environment $env, $string, $strategy = 'html', $ch
return htmlspecialchars($string, \ENT_QUOTES | \ENT_SUBSTITUTE, $charset);
}

$string = twig_convert_encoding($string, 'UTF-8', $charset);
$string = CoreExtension::convertEncoding($string, 'UTF-8', $charset);
$string = htmlspecialchars($string, \ENT_QUOTES | \ENT_SUBSTITUTE, 'UTF-8');

return iconv('UTF-8', $charset, $string);
Expand All @@ -265,7 +264,7 @@ public static function escape(Environment $env, $string, $strategy = 'html', $ch
// escape all non-alphanumeric characters
// into their \x or \uHHHH representations
if ('UTF-8' !== $charset) {
$string = twig_convert_encoding($string, 'UTF-8', $charset);
$string = CoreExtension::convertEncoding($string, 'UTF-8', $charset);
}

if (!preg_match('//u', $string)) {
Expand Down Expand Up @@ -316,7 +315,7 @@ public static function escape(Environment $env, $string, $strategy = 'html', $ch

case 'css':
if ('UTF-8' !== $charset) {
$string = twig_convert_encoding($string, 'UTF-8', $charset);
$string = CoreExtension::convertEncoding($string, 'UTF-8', $charset);
}

if (!preg_match('//u', $string)) {
Expand All @@ -337,7 +336,7 @@ public static function escape(Environment $env, $string, $strategy = 'html', $ch

case 'html_attr':
if ('UTF-8' !== $charset) {
$string = twig_convert_encoding($string, 'UTF-8', $charset);
$string = CoreExtension::convertEncoding($string, 'UTF-8', $charset);
}

if (!preg_match('//u', $string)) {
Expand Down Expand Up @@ -404,14 +403,14 @@ public static function escape(Environment $env, $string, $strategy = 'html', $ch
return rawurlencode($string);

default:
$escapers = $env->getExtension(EscaperExtension::class)->getEscapers();
$escapers = $env->getExtension(self::class)->getEscapers();
if (\array_key_exists($strategy, $escapers)) {
return $escapers[$strategy]($env, $string, $charset);
}

$validStrategies = implode(', ', array_merge(['html', 'js', 'url', 'css', 'html_attr'], array_keys($escapers)));
$validStrategies = implode('", "', array_merge(['html', 'js', 'url', 'css', 'html_attr'], array_keys($escapers)));

throw new RuntimeError(sprintf('Invalid escaping strategy "%s" (valid ones: %s).', $strategy, $validStrategies));
throw new RuntimeError(sprintf('Invalid escaping strategy "%s" (valid ones: "%s").', $strategy, $validStrategies));
}
}
}
2 changes: 1 addition & 1 deletion src/Extension/StringLoaderExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function getFunctions(): array
*
* @param string $template A template as a string or object implementing __toString()
* @param string $name An optional name of the template to be used in error messages
*
*
* @internal
*/
public static function templateFromString(Environment $env, $template, string $name = null): TemplateWrapper
Expand Down

0 comments on commit aa7c454

Please sign in to comment.