Skip to content

Commit

Permalink
array short syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
addfs committed Jun 8, 2022
1 parent 538d5e9 commit d825477
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 17 deletions.
14 changes: 7 additions & 7 deletions Builder/EnvironmentBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ class EnvironmentBuilder implements WarmableInterface
private $options;
private ?SecurityPolicy $policy;
private $rules;
private array $extensions = array();
private array $extensions = [];

public function __construct(LoaderInterface $loader, SecurityPolicy $policy = null, array $options = array())
public function __construct(LoaderInterface $loader, SecurityPolicy $policy = null, array $options = [])
{
$this->loader = $loader;
$this->policy = $policy;
Expand Down Expand Up @@ -61,7 +61,7 @@ public function addExtensions(array $extensions = null): void
/**
* Формирует окружение для Twig Sandbox
*/
public function getSandboxEnvironment($params = array(), SecurityPolicy $securityPolicy = null): TwigAdapter
public function getSandboxEnvironment($params = [], SecurityPolicy $securityPolicy = null): TwigAdapter
{
$loader = new ArrayLoader();
$twig = new Environment($loader, $params);
Expand All @@ -83,16 +83,16 @@ public function getSandboxEnvironment($params = array(), SecurityPolicy $securit

public function setOptions(array $options)
{
$this->options = array(
$this->options = [
'cache_dir' => null,
'cache_filename' => 'IntaroTwigSandboxPolicy',
'dumper_class' => null,
'bundles' => array(),
'bundles' => [],
'debug' => false,
);
];

// check option names and live merge, if errors are encountered Exception will be thrown
$invalid = array();
$invalid = [];
foreach ($options as $key => $value) {
if (array_key_exists($key, $this->options)) {
$this->options[$key] = $value;
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Require the bundle in your `composer.json` file:
```json
{
"require": {
"intaro/twig-sandbox-bundle": "^1.0",
"intaro/twig-sandbox-bundle": "^1.0"
}
}
```
Expand Down Expand Up @@ -383,6 +383,6 @@ class TwigSandboxPass implements CompilerPassInterface
}
$sandbox = $container->getDefinition('intaro.twig_sandbox.builder');
$sandbox->addMethodCall('addExtension', array(new Reference('acme_demo.twig_extension')));
$sandbox->addMethodCall('addExtension', [new Reference('acme_demo.twig_extension')]);
}
}
8 changes: 4 additions & 4 deletions SecurityPolicy/SecurityPolicyRules.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class SecurityPolicyRules
private $properties;
private $resources;

public function __construct(array $methods = array(), array $properties = array(), array $resources = array())
public function __construct(array $methods = [], array $properties = [], array $resources = [])
{
$this->methods = $methods;
$this->properties = $properties;
Expand All @@ -33,7 +33,7 @@ public function getProperties()
public function addMethod($class, $method)
{
if (!isset($this->methods[$class])) {
$this->methods[$class] = array();
$this->methods[$class] = [];
}

if (!in_array($method, $this->methods[$class])) {
Expand All @@ -44,7 +44,7 @@ public function addMethod($class, $method)
public function addProperty($class, $property)
{
if (!isset($this->properties[$class])) {
$this->properties[$class] = array();
$this->properties[$class] = [];
}

if (!in_array($property, $this->properties[$class])) {
Expand Down Expand Up @@ -88,4 +88,4 @@ public function merge(SecurityPolicyRules $rules)
}
}
}
}
}
8 changes: 4 additions & 4 deletions Validator/Constraints/TwigSandboxValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,16 @@ public function validate($value, Constraint $constraint)
catch (\Twig\Sandbox\SecurityError $e) {
$message = mb_strlen($e->getMessage()) > 150 ? mb_substr($e->getMessage(), 0, 150) . '' : $e->getMessage();

$this->context->addViolation($constraint->message, array(
$this->context->addViolation($constraint->message, [
'{{ syntax_error }}' => $message,
));
]);
}
catch (\Twig\Error\SyntaxError $e) {
$message = mb_strlen($e->getMessage()) > 150 ? mb_substr($e->getMessage(), 0, 150) . '' : $e->getMessage();

$this->context->addViolation($constraint->message, array(
$this->context->addViolation($constraint->message, [
'{{ syntax_error }}' => $message,
));
]);
}
catch (\Error $e) {
goto ex_r;
Expand Down

0 comments on commit d825477

Please sign in to comment.