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

Update brick/var-exporter to 0.5.0 and fix deprecations. #994

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
},
"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"
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
Loading