Skip to content

Commit

Permalink
add PHP CS Fixer code style configuration and make target, improve do…
Browse files Browse the repository at this point in the history
…cumentation
  • Loading branch information
rvanlaak committed Nov 16, 2021
1 parent 8d342db commit 0329051
Show file tree
Hide file tree
Showing 15 changed files with 207 additions and 160 deletions.
16 changes: 16 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
; top-most EditorConfig file
root = true

; Unix-style newlines
[*]
charset = utf-8
end_of_line = LF
insert_final_newline = true
trim_trailing_whitespace = true

[*.{php,html,twig}]
indent_style = space
indent_size = 4

[*.md]
max_line_length = 80
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,4 @@ jobs:

- name: Run tests
run: make test-lowest

24 changes: 24 additions & 0 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

if (!file_exists(__DIR__.'/src')) {
exit(0);
}

return (new PhpCsFixer\Config())
->setRules([
'@PHP71Migration' => true,
'@PHPUnit75Migration:risky' => true,
'@Symfony' => true,
'@Symfony:risky' => true,
'protected_to_private' => false,
'nullable_type_declaration_for_default_null_value' => ['use_nullable_type_declaration' => false],
])
->setRiskyAllowed(true)
->setFinder(
(new PhpCsFixer\Finder())
->in(__DIR__.'/src')
->notPath('#/Fixtures/#')
->in(__DIR__.'/tests')
->append([__FILE__])
)
;
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,6 @@ test-php73-lowest:

test-php74-lowest:
docker run --rm -v $(DIR):/project -w /project webdevops/php:7.4 $(MAKE) test-lowest

cs:
docker run --rm -v $(DIR):/project -w /project jakzal/phpqa php-cs-fixer fix
35 changes: 27 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,36 @@
Getting Started With BreadcrumbTrailBundle
==========================================

This bundle provides a breacrumb trail service also known as breadcrumbs or Fil d'Ariane.
Breadcrumbs can be defined with annotations, PHP and Twig.
This bundle provides a breadcrumb trail service also known as breadcrumbs or Fil d'Ariane.
Breadcrumbs can be defined with Attributes, annotations, PHP and Twig.

## Installation

Please follow the steps given in [installation.md](src/Resources/doc/installation.md) to install this bundle.

## Summary
## Bundle documentation

- [Annotation configuration](src/Resources/doc/annotation_configuration.md)
- [PHP configuration](src/Resources/doc/php_configuration.md)
- [Twig configuration](src/Resources/doc/twig_configuration.md)
- [Render the breadcrumb trail](src/Resources/doc/rendering.md)
- [Override the template](src/Resources/doc/override_template.md)
- [Annotation configuration](src/Resources/doc/annotation_configuration.md)
- [PHP configuration](src/Resources/doc/php_configuration.md)
- [Twig configuration](src/Resources/doc/twig_configuration.md)
- [Render the breadcrumb trail](src/Resources/doc/rendering.md)
- [Override the template](src/Resources/doc/override_template.md)

## Tests

Several make targets can get used to run the PHPUnit test suite on different PHP environments:

```
$ make test
$ make test-php73
$ make test-php74-lowest
```

## Code style

PHP-CS-Fixer is used to keep the code style in shape. There is a make target that uses Docker to fix
the code style without having to install any other dependencies:

```
$ make cs
```
57 changes: 27 additions & 30 deletions src/Annotation/Breadcrumb.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ class Breadcrumb
/**
* @var mixed An array of parameters for the route
*/
private $routeParameters = array();
private $routeParameters = [];

/**
* @var Boolean Whether to generate an absolute URL
* @var bool Whether to generate an absolute URL
*/
private $routeAbsolute = false;

/**
* @var integer Position of the breadcrumb (default = 0)
* @var int Position of the breadcrumb (default = 0)
*/
private $position = 0;

Expand All @@ -50,17 +50,17 @@ class Breadcrumb
/**
* @var mixed An array of additional attributes for the breadcrumb
*/
private $attributes = array();
private $attributes = [];

/**
* @param array|string $title title, or the legacy array that contains all annotation data
* @param array|string $title title, or the legacy array that contains all annotation data
* @param ?array<string, string|array> $route
* @param ?string $routeName
* @param ?array<string,mixed> $routeParameters
* @param bool $routeAbsolute
* @param int $position
* @param ?string $template
* @param array $attributes
* @param ?string $routeName
* @param ?array<string,mixed> $routeParameters
* @param bool $routeAbsolute
* @param int $position
* @param ?string $template
* @param array $attributes
*/
public function __construct(
$title,
Expand All @@ -70,13 +70,12 @@ public function __construct(
$position = null,
$template = null,
$attributes = null
)
{
) {
$data = [];

if (is_string($title)) {
$data = ["title" => $title];
} elseif (is_array($title)) {
if (\is_string($title)) {
$data = ['title' => $title];
} elseif (\is_array($title)) {
$data = $title;
}

Expand All @@ -99,32 +98,30 @@ public function __construct(
}

if (isset($data['route'])) {
if (is_array($data['route'])) {
if (\is_array($data['route'])) {
foreach ($data['route'] as $key => $value) {
$method = 'setRoute'.$key;
if (!method_exists($this, $method)) {
throw new \BadMethodCallException(sprintf("Unknown property '%s' for the 'route' parameter on annotation '%s'.", $key, get_class($this)));
throw new \BadMethodCallException(sprintf("Unknown property '%s' for the 'route' parameter on annotation '%s'.", $key, static::class));
}
$this->$method($value);
}
}
else {
} else {
$data['routeName'] = $data['route'];
}

unset($data['route']);
}

foreach ($data as $key => $value) {

// Do not attempt setting values that were provided as null
if ($value === null) {
if (null === $value) {
continue;
}

$method = 'set'.$key;
if (!method_exists($this, $method)) {
throw new \BadMethodCallException(sprintf("Unknown property '%s' on annotation '%s'.", $key, get_class($this)));
throw new \BadMethodCallException(sprintf("Unknown property '%s' on annotation '%s'.", $key, static::class));
}
$this->$method($value);
}
Expand All @@ -146,7 +143,7 @@ public function getTitle()
}

/**
* Sets the name of the route
* Sets the name of the route.
*
* @param string $routeName The name of the route
*/
Expand All @@ -161,7 +158,7 @@ public function getRouteName()
}

/**
* Sets an array of parameters for the route
* Sets an array of parameters for the route.
*
* @param mixed $routeParameters An array of parameters for the route
*/
Expand All @@ -176,9 +173,9 @@ public function getRouteParameters()
}

/**
* Whether to generate an absolute URL
* Whether to generate an absolute URL.
*
* @param Boolean $routeName Whether to generate an absolute URL
* @param bool $routeName Whether to generate an absolute URL
*/
public function setRouteAbsolute($routeAbsolute)
{
Expand All @@ -193,7 +190,7 @@ public function getRouteAbsolute()
/**
* Sets the position of the breadcrumb.
*
* @param integer Position of the breadcrumb (default = 0)
* @param int Position of the breadcrumb (default = 0)
*/
public function setPosition($position)
{
Expand All @@ -208,7 +205,7 @@ public function getPosition()
/**
* Sets the template of the breadcrumb trail.
*
* @param string Template of the breadcrumb trail.
* @param string template of the breadcrumb trail
*/
public function setTemplate($template)
{
Expand All @@ -223,7 +220,7 @@ public function getTemplate()
/**
* Sets the additional attributes for the breadcrumb.
*
* @param mixed Additional attributes for the breadcrumb.
* @param mixed additional attributes for the breadcrumb
*/
public function setAttributes($attributes)
{
Expand Down
8 changes: 4 additions & 4 deletions src/BreadcrumbTrail/Breadcrumb.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ class Breadcrumb
/**
* Constructor.
*
* @param string $title Title of the breadcrumb
* @param string $url Url of the breadcrumb
* @param mixed $attributes Additional attributes for the breadcrumb
* @param string $title Title of the breadcrumb
* @param string $url Url of the breadcrumb
* @param mixed $attributes Additional attributes for the breadcrumb
*/
public function __construct($title, $url = null, $attributes = array())
public function __construct($title, $url = null, $attributes = [])
{
$this->title = $title;
$this->url = $url;
Expand Down
Loading

0 comments on commit 0329051

Please sign in to comment.