Skip to content

Commit

Permalink
Merge pull request #995 from QoboLtd/3.next
Browse files Browse the repository at this point in the history
Update brick/var-exporter to 0.5.0 and fix deprecations. [3.next]
  • Loading branch information
dereuromark authored Jul 3, 2024
2 parents 97e6077 + 4976c24 commit ac6992c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 17 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
},
"require": {
"php": ">=8.1",
"brick/varexporter": "^0.4.0",
"brick/varexporter": "^0.5.0",
"cakephp/cakephp": "^5.0.3",
"cakephp/twig-view": "^2.0.0",
"nikic/php-parser": "^4.13.2 || ^5.0.0"
"nikic/php-parser": "^5.0.0"
},
"require-dev": {
"cakephp/cakephp-codesniffer": "^5.0.0",
Expand Down
27 changes: 14 additions & 13 deletions src/CodeGen/CodeParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,19 @@
namespace Bake\CodeGen;

use PhpParser\Error;
use PhpParser\Lexer\Emulative;
use PhpParser\Node;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\GroupUse;
use PhpParser\Node\Stmt\Namespace_;
use PhpParser\Node\Stmt\Use_;
use PhpParser\Node\Stmt\UseUse;
use PhpParser\Node\UseItem;
use PhpParser\NodeAbstract;
use PhpParser\NodeTraverser;
use PhpParser\NodeVisitor;
use PhpParser\NodeVisitorAbstract;
use PhpParser\Parser;
use PhpParser\ParserFactory;
use PhpParser\PhpVersion;

/**
* @internal
Expand Down Expand Up @@ -65,12 +66,8 @@ class CodeParser extends NodeVisitorAbstract
*/
public function __construct()
{
$this->parser = (new ParserFactory())->create(
ParserFactory::PREFER_PHP7,
new Emulative([
'usedAttributes' => ['comments', 'startLine', 'endLine', 'startFilePos', 'endFilePos'],
])
);
$version = PhpVersion::fromComponents(8, 1);
$this->parser = (new ParserFactory())->createForVersion($version);
$this->traverser = new NodeTraverser();
$this->traverser->addVisitor($this);
}
Expand Down Expand Up @@ -137,7 +134,11 @@ public function enterNode(Node $node)
throw new ParseException('Multiple use statements per line are not supported, update your file');
}

[$alias, $target] = $this->normalizeUse(current($node->uses));
if ($node->uses === []) {
throw new ParseException('Use statement without uses!');
}

[$alias, $target] = $this->normalizeUse($node->uses[0]);
switch ($node->type) {
case Use_::TYPE_NORMAL:
$this->parsed['imports']['class'][$alias] = $target;
Expand All @@ -150,7 +151,7 @@ public function enterNode(Node $node)
break;
}

return NodeTraverser::DONT_TRAVERSE_CHILDREN;
return NodeVisitor::DONT_TRAVERSE_CHILDREN;
}

if ($node instanceof GroupUse) {
Expand Down Expand Up @@ -203,7 +204,7 @@ public function enterNode(Node $node)
$methods
);

return NodeTraverser::DONT_TRAVERSE_CHILDREN;
return NodeVisitor::DONT_TRAVERSE_CHILDREN;
}

return null;
Expand All @@ -230,11 +231,11 @@ protected function getNodeCode(NodeAbstract $node): string
}

/**
* @param \PhpParser\Node\Stmt\UseUse $use Use node
* @param \PhpParser\Node\UseItem $use Use item
* @param string|null $prefix Group use prefix
* @return array{string, string}
*/
protected function normalizeUse(UseUse $use, ?string $prefix = null): array
protected function normalizeUse(UseItem $use, ?string $prefix = null): array
{
$name = (string)$use->name;
if ($prefix) {
Expand Down
4 changes: 2 additions & 2 deletions src/View/Helper/BakeHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public function exportArray(array $var, int $indentLevel = 0, bool $inline = tru
{
$options = 0;
if ($inline) {
$options = VarExporter::INLINE_NUMERIC_SCALAR_ARRAY;
$options = VarExporter::INLINE_SCALAR_LIST;
}

return $this->exportVar($var, $indentLevel, $options);
Expand Down Expand Up @@ -369,7 +369,7 @@ public function getValidationMethods(string $field, array $rules): array
return $this->exportVar(
$item,
is_array($item) ? 3 : 0,
VarExporter::INLINE_NUMERIC_SCALAR_ARRAY
VarExporter::INLINE_SCALAR_LIST
);
}, $rule['args']);
$validationMethods[] = sprintf(
Expand Down

0 comments on commit ac6992c

Please sign in to comment.