Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into expression-language…
Browse files Browse the repository at this point in the history
…-poc
  • Loading branch information
mpdude committed Jul 1, 2024
2 parents b4813d1 + 63c4e68 commit cf8e06a
Show file tree
Hide file tree
Showing 23 changed files with 154 additions and 138 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/fix-cs-php.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Update this by running
# curl https://gist.github.com/mpdude/ca93a185bcbf56eb7e341632ad4f8263/raw/fix-cs-php.yml > .github/workflows/fix-cs-php.yml

on:
push:
branches:
- master
pull_request:

name: Coding Standards

jobs:
fix-cs-issues:
name: PHP-CS-Fixer
runs-on: ubuntu-22.04
if: github.actor != 'dependabot[bot]'
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}

- name: Run PHP-CS-Fixer
uses: docker://oskarstark/php-cs-fixer-ga

- name: Commit and push back changes
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: "Fix CS with PHP-CS-Fixer"
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ vendor/
phpunit.xml
composer.lock
.phpunit.result.cache
.php-cs-fixer.cache
19 changes: 19 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

return (new PhpCsFixer\Config())
->setRules([
'@Symfony' => true,
'@Symfony:risky' => true,
'array_syntax' => array('syntax' => 'short'),
'no_unreachable_default_argument_value' => false,
'braces' => array('allow_single_line_closure' => true),
'heredoc_to_nowdoc' => false,
'psr_autoloading' => false,
])
->setRiskyAllowed(true)
->setFinder(
PhpCsFixer\Finder::create()
->in(__DIR__)
->notPath('vendor/')
)
;
10 changes: 5 additions & 5 deletions src/JMS/ObjectRouting/Attribute/ObjectRoute.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

/*
* Copyright 2013 Johannes M. Schmitt <schmittjoh@gmail.com>
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand All @@ -28,10 +28,10 @@ final class ObjectRoute
public $name;

/** @var array */
public $params = array();
public $params = [];

/** @var array */
public $paramExpressions = array();
public $paramExpressions = [];

public function __construct(string $type, string $name, array $params = [], array $paramExpressions = [])
{
Expand Down
4 changes: 1 addition & 3 deletions src/JMS/ObjectRouting/Exception/Exception.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace JMS\ObjectRouting\Exception;


interface Exception
{

}
}
4 changes: 1 addition & 3 deletions src/JMS/ObjectRouting/Exception/RuntimeException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace JMS\ObjectRouting\Exception;


class RuntimeException extends \RuntimeException implements Exception
{

}
}
9 changes: 4 additions & 5 deletions src/JMS/ObjectRouting/Exception/XmlErrorException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,20 @@

namespace JMS\ObjectRouting\Exception;


class XmlErrorException extends RuntimeException
{
private $xmlError;

public function __construct(\LibXMLError $error)
{
switch ($error->level) {
case LIBXML_ERR_WARNING:
case \LIBXML_ERR_WARNING:
$level = 'WARNING';
break;
case LIBXML_ERR_FATAL:
case \LIBXML_ERR_FATAL:
$level = 'FATAL';
break;
case LIBXML_ERR_ERROR:
case \LIBXML_ERR_ERROR:
$level = 'ERROR';
break;
default:
Expand All @@ -30,4 +29,4 @@ public function getXmlError()
{
return $this->xmlError;
}
}
}
21 changes: 10 additions & 11 deletions src/JMS/ObjectRouting/Metadata/ClassMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

/*
* Copyright 2013 Johannes M. Schmitt <schmittjoh@gmail.com>
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand All @@ -23,15 +23,15 @@

class ClassMetadata extends MergeableClassMetadata
{
public $routes = array();
public $routes = [];

public function addRoute($type, $name, array $params = array(), array $paramExpressions = array())
public function addRoute($type, $name, array $params = [], array $paramExpressions = [])
{
$this->routes[$type] = array(
$this->routes[$type] = [
'name' => $name,
'params' => $params,
'paramExpressions' => $paramExpressions,
);
];
}

public function merge(MergeableInterface $object): void
Expand All @@ -43,10 +43,10 @@ public function merge(MergeableInterface $object): void
public function serialize(): string
{
return serialize(
array(
[
$this->routes,
parent::serialize(),
)
]
);
}

Expand All @@ -55,9 +55,8 @@ public function unserialize($str): void
list(
$this->routes,
$parentStr
) = unserialize($str);
) = unserialize($str);

parent::unserialize($parentStr);
}

}
6 changes: 3 additions & 3 deletions src/JMS/ObjectRouting/Metadata/Driver/AttributeDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

/*
* Copyright 2013 Johannes M. Schmitt <schmittjoh@gmail.com>
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand Down
5 changes: 2 additions & 3 deletions src/JMS/ObjectRouting/Metadata/Driver/PhpDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,13 @@

namespace JMS\ObjectRouting\Metadata\Driver;


use JMS\ObjectRouting\Exception\RuntimeException;
use JMS\ObjectRouting\Metadata\ClassMetadata;
use Metadata\Driver\AbstractFileDriver;

/**
* Class PhpDriver
* @package JMS\ObjectRouting\Metadata\Driver
* Class PhpDriver.
*
* @author Sebastian Kroczek <sk@xbug.de>
*/
class PhpDriver extends AbstractFileDriver
Expand Down
27 changes: 10 additions & 17 deletions src/JMS/ObjectRouting/Metadata/Driver/XmlDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,21 @@

namespace JMS\ObjectRouting\Metadata\Driver;


use JMS\ObjectRouting\Exception\RuntimeException;
use JMS\ObjectRouting\Exception\XmlErrorException;
use JMS\ObjectRouting\Metadata\ClassMetadata;
use Metadata\Driver\AbstractFileDriver;

/**
* Class XmlDriver
* @package JMS\ObjectRouting\Metadata\Driver
* Class XmlDriver.
*
* @author Sebastian Kroczek <sk@xbug.de>
*/
class XmlDriver extends AbstractFileDriver
{

/**
* Parses the content of the file, and converts it to the desired metadata.
*
* @param \ReflectionClass $class
* @param string $file
*
* @return \Metadata\ClassMetadata|null
*/
protected function loadMetadataFromFile(\ReflectionClass $class, string $file): ?ClassMetadata
Expand All @@ -57,28 +52,28 @@ protected function loadMetadataFromFile(\ReflectionClass $class, string $file):
$metadata->fileResources[] = $class->getFileName();

if (null !== $xmlRootName = $elem->attributes()->{'xml-root-name'}) {
$metadata->xmlRootName = (string)$xmlRootName;
$metadata->xmlRootName = (string) $xmlRootName;
}
if (null !== $xmlRootNamespace = $elem->attributes()->{'xml-root-namespace'}) {
$metadata->xmlRootNamespace = (string)$xmlRootNamespace;
$metadata->xmlRootNamespace = (string) $xmlRootNamespace;
}

foreach ($elem->xpath('./route') as $r) {
if ('' === $type = (string)$r->attributes()->{'type'}) {
if ('' === $type = (string) $r->attributes()->{'type'}) {
throw new RuntimeException('Could not find attribute "type" inside XML element.');
}
if ('' === $name = (string)$r->attributes()->{'name'}) {
if ('' === $name = (string) $r->attributes()->{'name'}) {
throw new RuntimeException('Could not find attribute "name" inside XML element.');
}

$params = array();
$params = [];
foreach ($r->xpath('./param') as $p) {
$params[(string)$p->attributes()] = (string)$p;
$params[(string) $p->attributes()] = (string) $p;
}

$paramExpressions = array();
$paramExpressions = [];
foreach ($r->xpath('./paramExpression') as $p) {
$paramExpressions[(string)$p->attributes()] = (string)$p;
$paramExpressions[(string) $p->attributes()] = (string) $p;
}

$metadata->addRoute($type, $name, $params, $paramExpressions);
Expand All @@ -89,8 +84,6 @@ protected function loadMetadataFromFile(\ReflectionClass $class, string $file):

/**
* Returns the extension of the file.
*
* @return string
*/
protected function getExtension(): string
{
Expand Down
19 changes: 5 additions & 14 deletions src/JMS/ObjectRouting/Metadata/Driver/YamlDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,15 @@
use Symfony\Component\Yaml\Yaml;

/**
* Class YamlDriver
* @package JMS\ObjectRouting\Metadata\Driver
* Class YamlDriver.
*
* @author Sebastian Kroczek <sk@xbug.de>
*/
class YamlDriver extends AbstractFileDriver
{


/**
* Parses the content of the file, and converts it to the desired metadata.
*
* @param \ReflectionClass $class
* @param string $file
*
* @return \Metadata\ClassMetadata|null
*/
protected function loadMetadataFromFile(\ReflectionClass $class, string $file): ?ClassMetadata
Expand All @@ -48,32 +43,28 @@ protected function loadMetadataFromFile(\ReflectionClass $class, string $file):
throw new RuntimeException(sprintf('Expected metadata for class %s to be defined in %s.', $class->name, $file));
}


$config = $config[$name];
$metadata = new ClassMetadata($name);
$metadata->fileResources[] = $file;
$metadata->fileResources[] = $class->getFileName();

foreach ($config as $type => $value) {
if (!array_key_exists('name', $value)) {
if (!\array_key_exists('name', $value)) {
throw new RuntimeException('Could not find key "type" inside yaml element.');
}
$metadata->addRoute(
$type,
$value['name'],
array_key_exists('params', $value) ? $value['params'] : array(),
array_key_exists('paramExpressions', $value) ? $value['paramExpressions'] : array()
\array_key_exists('params', $value) ? $value['params'] : [],
\array_key_exists('paramExpressions', $value) ? $value['paramExpressions'] : []
);
}

return $metadata;

}

/**
* Returns the extension of the file.
*
* @return string
*/
protected function getExtension(): string
{
Expand Down
Loading

0 comments on commit cf8e06a

Please sign in to comment.