Skip to content

Commit

Permalink
Rework version 2 (#4)
Browse files Browse the repository at this point in the history
* Rework version 2

* uppdate readme file

* update more helper files

* Remove badges

* Update changelog

* Added funding and composer normalizer

* Improve travis
  • Loading branch information
gmponos authored Jul 25, 2020
1 parent db84913 commit 5236238
Show file tree
Hide file tree
Showing 17 changed files with 187 additions and 98 deletions.
8 changes: 7 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
; This file is for unifying the coding style for different editors and IDEs.
; More information at https://editorconfig.org

root = true

[*]
charset = utf-8
end_of_line = lf
indent_size = 4
indent_style = space
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

[Makefile]
indent_style = tab
25 changes: 15 additions & 10 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
/.editorconfig export-ignore
/.gitattributes export-ignore
/.github/ export-ignore
/.gitignore export-ignore
/.php_cs export-ignore
/.scrutinizer.yml export-ignore
/.styleci.yml export-ignore
/.travis.yml export-ignore
/phpunit.xml.dist export-ignore
/tests/ export-ignore
# Path-based git attributes
# https://www.kernel.org/pub/software/scm/git/docs/gitattributes.html

# Ignore all test and documentation with "export-ignore".
/.github export-ignore
/bin export-ignore
/tests export-ignore

/.editorconfig export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/.php_cs export-ignore
/.travis.yml export-ignore
/Makefile export-ignore
/phpunit.xml.dist export-ignore
3 changes: 3 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# These are supported funding model platforms

github: [gmponos, sagikazarmark]
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
/build/
/composer.lock
/phpunit.xml
/vendor/

### phpunit
.phpunit.result.cache
/phpunit.xml
65 changes: 61 additions & 4 deletions .php_cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,64 @@
<?php

require_once __DIR__.'/vendor/sllh/php-cs-fixer-styleci-bridge/autoload.php';
$finder = PhpCsFixer\Finder::create()
->in([
__DIR__ . '/src',
__DIR__ . '/tests',
]);

use SLLH\StyleCIBridge\ConfigBridge;

return ConfigBridge::create();
return PhpCsFixer\Config::create()
->setRiskyAllowed(true)
->setUsingCache(false)
->setRules([
'declare_strict_types' => true,
'final_class' => true,
'final_static_access' => true,
'function_to_constant' => true,
'native_constant_invocation' => true,
'native_function_invocation' => ['include' => ['@all']],
'no_alternative_syntax' => true,
'no_empty_phpdoc' => true,
'no_extra_blank_lines' => true,
'no_superfluous_phpdoc_tags' => ['allow_mixed' => true],
'no_trailing_comma_in_singleline_array' => true,
'no_trailing_whitespace' => true,
'no_trailing_whitespace_in_comment' => true,
'no_unneeded_control_parentheses' => true,
'no_useless_else' => true,
'no_useless_return' => true,
'no_whitespace_before_comma_in_array' => true,
'no_whitespace_in_blank_line' => true,
'normalize_index_brace' => true,
'php_unit_construct' => true,
'php_unit_dedicate_assert' => ['target' => 'newest'],
'php_unit_dedicate_assert_internal_type' => ['target' => 'newest'],
'php_unit_mock' => ['target' => 'newest'],
'php_unit_mock_short_will_return' => true,
'php_unit_ordered_covers' => true,
'php_unit_set_up_tear_down_visibility' => true,
'php_unit_test_annotation' => ['style' => 'annotation', 'case' => 'camel'],
'php_unit_test_case_static_method_calls' => ['call_type' => 'this'],
'phpdoc_align' => ['align' => 'left'],
'phpdoc_line_span' => ['method' => 'multi', 'property' => 'multi'],
'phpdoc_no_package' => true,
'phpdoc_no_useless_inheritdoc' => true,
'phpdoc_scalar' => true,
'phpdoc_single_line_var_spacing' => true,
'phpdoc_trim' => true,
'phpdoc_trim_consecutive_blank_line_separation' => true,
'phpdoc_types' => true,
'phpdoc_types_order' => ['null_adjustment' => 'always_last', 'sort_algorithm' => 'none'],
'phpdoc_var_annotation_correct_order' => true,
'phpdoc_var_without_name' => true,
'protected_to_private' => true,
'random_api_migration' => true,
'return_assignment' => true,
'single_trait_insert_per_statement' => true,
'standardize_not_equals' => true,
'static_lambda' => true,
'ternary_to_null_coalescing' => true,
'trim_array_spaces' => true,
'void_return' => true,
'whitespace_after_comma_in_array' => true,
])
->setFinder($finder);
8 changes: 0 additions & 8 deletions .scrutinizer.yml

This file was deleted.

9 changes: 0 additions & 9 deletions .styleci.yml

This file was deleted.

27 changes: 8 additions & 19 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,9 @@ cache:
- $HOME/.composer/cache/files

php:
- 5.4
- 5.5
- 5.6
- 7.0
- hhvm

env:
global:
- TEST_COMMAND="composer test"
- 7.2
- 7.3
- 7.4

branches:
except:
Expand All @@ -24,18 +18,13 @@ branches:
matrix:
fast_finish: true
include:
- php: 5.4
env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest" COVERAGE=true TEST_COMMAND="composer test-ci"

before_install:
- if [[ $COVERAGE != true && $TRAVIS_PHP_VERSION != hhvm ]]; then phpenv config-rm xdebug.ini; fi
- php: 7.2
env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest"

install:
- travis_retry composer update ${COMPOSER_FLAGS} --prefer-dist --no-interaction

script:
- $TEST_COMMAND

after_success:
- if [[ "$COVERAGE" = true ]]; then wget https://scrutinizer-ci.com/ocular.phar; fi
- if [[ "$COVERAGE" = true ]]; then php ocular.phar code-coverage:upload --format=php-clover build/coverage.xml; fi
- make lint-php
- make php-cs-fixer-dry
- make phpunit
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Change Log
# Changelog

## 2.0.0 - 2020-07-25

### Changed
- Minimum PHP version required is 7.2.
- Updated to allow newer versions of twig.
- Made all classes final.

## 1.0.0 - 2016-06-25

Expand Down
17 changes: 17 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
lint-php:
@files=$$(find . -type f -name "*.php" | grep -v '/vendor/'); \
for f in $${files}; do \
php -l $$f; \
done

php-cs-fixer:
php ./bin/php-cs-fixer.phar fix -v

php-cs-fixer-dry:
php bin/php-cs-fixer.phar fix -v --dry-run --diff --diff-format=udiff

composer-normalize:
php bin/composer-normalize.phar --no-update-lock

phpunit:
php vendor/bin/phpunit --colors=always
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@

[![Latest Version](https://img.shields.io/github/release/gravatarphp/twig-integration.svg?style=flat-square)](https://github.com/gravatarphp/twig-integration/releases)
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE)
[![Build Status](https://img.shields.io/travis/gravatarphp/twig-integration.svg?style=flat-square)](https://travis-ci.org/gravatarphp/twig-integration)
[![Code Coverage](https://img.shields.io/scrutinizer/coverage/g/gravatarphp/twig-integration.svg?style=flat-square)](https://scrutinizer-ci.com/g/gravatarphp/twig-integration)
[![Quality Score](https://img.shields.io/scrutinizer/g/gravatarphp/twig-integration.svg?style=flat-square)](https://scrutinizer-ci.com/g/gravatarphp/twig-integration)
[![Build Status](https://img.shields.io/travis/gravatarphp/twig-integration.svg?style=flat-square)](https://travis-ci.com/gravatarphp/twig-integration)
[![Total Downloads](https://img.shields.io/packagist/dt/gravatarphp/twig-integration.svg?style=flat-square)](https://packagist.org/packages/gravatarphp/twig-integration)

**Integrates Gravatar into Twig templating engine.**


## Install

Via Composer
Expand Down Expand Up @@ -58,6 +55,7 @@ $ composer test
## Credits

- [Márk Sági-Kazár](https://github.com/sagikazarmark)
- [George Mponos](https://github.com/gmponos)
- [All Contributors](https://github.com/gravatarphp/twig-integration/contributors)


Expand Down
Binary file added bin/composer-normalize.phar
Binary file not shown.
Binary file added bin/php-cs-fixer.phar
Binary file not shown.
40 changes: 23 additions & 17 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,39 +1,45 @@
{
"name": "gravatarphp/twig-integration",
"description": "Integrates Gravatar into Twig templating engine",
"license": "MIT",
"keywords": ["gravatar", "twig"],
"keywords": [
"gravatar",
"twig"
],
"homepage": "http://gravatarphp.com",
"license": "MIT",
"authors": [
{
"name": "Márk Sági-Kazár",
"email": "[email protected]"
},
{
"name": "George Mponos",
"email": "[email protected]"
}
],
"require": {
"php": ">=5.4",
"gravatarphp/gravatar": "^1.0",
"twig/twig": "^1.18"
"php": ">=7.2",
"gravatarphp/gravatar": "^2.0",
"twig/twig": "^1.43 || ^2.13 || ^3.0"
},
"require-dev": {
"phpunit/phpunit": "^4.8 || ^5.0",
"sllh/php-cs-fixer-styleci-bridge": "^2.0",
"friendsofphp/php-cs-fixer": "^1.11"
"phpunit/phpunit": "^8.5.8 || ^9.2.0"
},
"extra": {
"branch-alias": {
"dev-master": "2.0-dev"
}
},
"autoload": {
"psr-4": {
"Gravatar\\Twig\\": "src/"
}
},
"scripts": {
"test": "vendor/bin/phpunit",
"test-ci": "vendor/bin/phpunit --coverage-text --coverage-clover=build/coverage.xml"
},
"extra": {
"branch-alias": {
"dev-master": "1.0-dev"
"autoload-dev": {
"psr-4": {
"Gravatar\\Twig\\Tests\\": "tests"
}
},
"prefer-stable": true,
"minimum-stability": "dev"
"minimum-stability": "dev",
"prefer-stable": true
}
20 changes: 19 additions & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit colors="true" bootstrap="vendor/autoload.php">
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php"
beStrictAboutOutputDuringTests="true"
cacheResult="false"
colors="true"
executionOrder="random"
failOnRisky="true"
failOnWarning="true"
verbose="true"
>
<testsuites>
<testsuite name="Gravatar Twig Test Suite">
<directory>tests/</directory>
Expand All @@ -8,6 +18,14 @@
<filter>
<whitelist>
<directory suffix=".php">src/</directory>
<exclude>
<directory suffix="Interface.php">src/</directory>
</exclude>
</whitelist>
</filter>

<logging>
<log type="coverage-html" target="build/coverage" highLowerBound="90" />
<log type="coverage-text" target="build/coverage.txt" highLowerBound="90" showOnlySummary="true" />
</logging>
</phpunit>
31 changes: 12 additions & 19 deletions src/GravatarExtension.php
Original file line number Diff line number Diff line change
@@ -1,46 +1,39 @@
<?php

declare(strict_types=1);

namespace Gravatar\Twig;

use Gravatar\Gravatar;
use Twig\Extension\AbstractExtension;
use Twig\TwigFilter;

/**
* Gravatar Twig extension.
*
* @author Márk Sági-Kazár <[email protected]>
*/
class GravatarExtension extends \Twig_Extension
final class GravatarExtension extends AbstractExtension
{
/**
* @var Gravatar
*/
protected $gravatar;
private $gravatar;

/**
* @param Gravatar $gravatar
*/
public function __construct(Gravatar $gravatar)
{
$this->gravatar = $gravatar;
}

/**
* {@inheritdoc}
*/
public function getFilters()
public function getFilters(): array
{
return [
new \Twig_SimpleFilter('gravatar_avatar', [$this->gravatar, 'avatar']),
new \Twig_SimpleFilter('gravatar_profile', [$this->gravatar, 'profile']),
new \Twig_SimpleFilter('gravatar_vcard', [$this->gravatar, 'vcard']),
new \Twig_SimpleFilter('gravatar_qrCode', [$this->gravatar, 'qrCode']),
new TwigFilter('gravatar_avatar', [$this->gravatar, 'avatar']),
new TwigFilter('gravatar_profile', [$this->gravatar, 'profile']),
new TwigFilter('gravatar_vcard', [$this->gravatar, 'vcard']),
new TwigFilter('gravatar_qrCode', [$this->gravatar, 'qrCode']),
];
}

/**
* {@inheritdoc}
*/
public function getName()
public function getName(): string
{
return 'gravatar';
}
Expand Down
Loading

0 comments on commit 5236238

Please sign in to comment.