Skip to content

Commit

Permalink
Merge pull request #14 from neveldo/chore/upgrade-dependencies
Browse files Browse the repository at this point in the history
chore: update PHP version, update dependencies, improve code quality
  • Loading branch information
neveldo authored Oct 23, 2024
2 parents e8e0229 + 8181383 commit 35425bc
Show file tree
Hide file tree
Showing 37 changed files with 641 additions and 728 deletions.
5 changes: 4 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
/tests/ export-ignore
/tests/ export-ignore
/sample/ export-ignore
/phpunit.xml.dist export-ignore
/Dockerfile export-ignore
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
vendor/
.idea/
.DS_Store
composer.lock
composer.lock
.phpunit.result.cache
12 changes: 12 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM php:8.2-cli

RUN apt-get update && apt-get install -y \
unzip \
git \
&& rm -rf /var/lib/apt/lists/*

COPY --from=composer:2 /usr/bin/composer /usr/bin/composer

WORKDIR /app

CMD ["bash"]
52 changes: 33 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ Data :

[
[
'my_choice' => 2,
'my_choice' => '2',
]
]

Expand Down Expand Up @@ -206,7 +206,7 @@ Data :
[
[
'my_tag1' => '',
'my_tag2' => null,
'my_tag2' => '',
'my_tag3' => 'Hello',
'my_tag4' => 'Hi',
]
Expand Down Expand Up @@ -270,58 +270,58 @@ Data :
'nationality' => 'American',
'birth_city' => 'Hollywood',
'birth_country' => 'US',
'awards_number' => 1,
'nominations_number' => 6,
'movies_number' => 37,
'awards_number' => '1',
'nominations_number' => '6',
'movies_number' => '37',
'first_movie_name' => 'Critters 3',
'first_movie_year' => 1991,
'first_movie_year' => '1991',
'famous_movie_name' => 'Titanic',
'famous_movie_year' => 1997,
'famous_movie_year' => '1997',
'famous_movie_earn' => '2185372302',
'other_famous_movies' => [
[
'name' => 'Catch Me If You Can',
'year' => 2002
'year' => '2002'
],
[
'name' => 'Shutter Island',
'year' => 2010
'year' => '2010'
],
[
'name' => 'Inception',
'year' => 2010
'year' => '2010'
],
]
],
[
'firstname' => 'Jodie',
'lastname' => 'Foster',
'birthdate' => 'November 19, 1962',
'age' => 51,
'age' => '51',
'sex' => 'f',
'nationality' => 'American',
'birth_city' => 'Los Angeles',
'birth_country' => 'US',
'awards_number' => 2,
'nominations_number' => 4,
'movies_number' => 75,
'awards_number' => '2',
'nominations_number' => '4',
'movies_number' => '75',
'first_movie_name' => 'My Sister Hank',
'first_movie_year' => 1972,
'first_movie_year' => '1972',
'famous_movie_name' => 'Taxi Driver',
'famous_movie_year' => 1976,
'famous_movie_year' => '1976',
'famous_movie_earn' => '28262574',
'other_famous_movies' => [
[
'name' => 'The Silence of the Lambs',
'year' => 1991
'year' => '1991'
],
[
'name' => 'Contact',
'year' => null // Empty values are skipped by the parser
'year' => '' // Empty values are skipped by the parser
],
[
'name' => 'The Accused',
'year' => 1988
'year' => '1988'
],
]
],
Expand All @@ -340,3 +340,17 @@ You can extend the TextGenerator capabilities by adding your own text funtions.
## Install

$ composer require neveldo/text-generator

## Running tests and linters

```
docker build -t text-generator .
docker run -it --rm -v $(pwd):/app text-generator
```

```
composer install
vendor/bin/phpunit --display-deprecations
vendor/bin/phpstan analyse src tests sample -l 9
vendor/bin/php-cs-fixer fix src
```
10 changes: 6 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
"type": "library",
"license": "MIT",
"require": {
"php": ">=8.1.0",
"symfony/expression-language": "^3.0|^4.0",
"ruafozy/mersenne-twister": "^2"
"php": ">=8.2.0",
"symfony/expression-language": "^6.0|^7.0",
"ruafozy/mersenne-twister": "^2.0"
},
"require-dev": {
"phpunit/phpunit": "^6.0"
"phpunit/phpunit": "^11.0",
"phpstan/phpstan": "^1.12",
"friendsofphp/php-cs-fixer": "^3.64"
},
"autoload": {
"psr-4" : {
Expand Down
6 changes: 0 additions & 6 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,8 @@
<phpunit
bootstrap="tests/bootstrap.php"
colors="true"
verbose="true"
>
<testsuite name="TextGenerator tests">
<directory>tests</directory>
</testsuite>
<filter>
<whitelist addUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./src</directory>
</whitelist>
</filter>
</phpunit>
5 changes: 3 additions & 2 deletions sample/src/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,14 @@
$textGenerator->compile($_POST['template']);

try {
$data = json_decode($_POST['data'], true);
/** @var array<array<string>> */
$data = json_decode((string) $_POST['data'], true);

foreach($data as $row) {
$output['result'][] = $textGenerator->generate($row);
}

} catch (\Exception $e) {
} catch (Exception $e) {
$output['error'] = $e->getMessage();
}
}
Expand Down
38 changes: 19 additions & 19 deletions sample/src/run.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,63 +31,63 @@
'firstname' => 'Leonardo',
'lastname' => 'DiCaprio',
'birthdate' => 'November 11, 1974',
'age' => 41,
'age' => '41',
'sex' => 'm',
'nationality' => 'American',
'birth_city' => 'Hollywood',
'birth_country' => 'US',
'awards_number' => 1,
'nominations_number' => 6,
'movies_number' => 37,
'awards_number' => '1',
'nominations_number' => '6',
'movies_number' => '37',
'first_movie_name' => 'Critters 3',
'first_movie_year' => 1991,
'first_movie_year' => '1991',
'famous_movie_name' => 'Titanic',
'famous_movie_year' => 1997,
'famous_movie_year' => '1997',
'famous_movie_earn' => '2185372302',
'other_famous_movies' => [
[
'name' => 'Catch Me If You Can',
'year' => 2002
'year' => '2002'
],
[
'name' => 'Shutter Island',
'year' => 2010
'year' => '2010'
],
[
'name' => 'Inception',
'year' => 2010
'year' => '2010'
],
]
],
[
'firstname' => 'Jodie',
'lastname' => 'Foster',
'birthdate' => 'November 19, 1962',
'age' => 51,
'age' => '51',
'sex' => 'f',
'nationality' => 'American',
'birth_city' => 'Los Angeles',
'birth_country' => 'US',
'awards_number' => 2,
'nominations_number' => 4,
'movies_number' => 75,
'awards_number' => '2',
'nominations_number' => '4',
'movies_number' => '75',
'first_movie_name' => 'My Sister Hank',
'first_movie_year' => 1972,
'first_movie_year' => '1972',
'famous_movie_name' => 'Taxi Driver',
'famous_movie_year' => 1976,
'famous_movie_year' => '1976',
'famous_movie_earn' => '28262574',
'other_famous_movies' => [
[
'name' => 'The Silence of the Lambs',
'year' => 1991
'year' => '1991'
],
[
'name' => 'Contact',
'year' => null // Empty values are skipped by the parser
'year' => '' // Empty values are skipped by the parser
],
[
'name' => 'The Accused',
'year' => 1988
'year' => '1988'
],
]
],
Expand All @@ -98,4 +98,4 @@

foreach($data as $row) {
echo $textGenerator->generate($row) . "\n\n";
}
}
6 changes: 3 additions & 3 deletions src/TextGenerator/ExpressionLanguage/ExpressionLanguage.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
namespace Neveldo\TextGenerator\ExpressionLanguage;

/**
* Class TagReplacerInterface
* Class ExpressionLanguage
* Handle tags replacement within a text
* @package Neveldo\TextGenerator\Tag
* @package Neveldo\TextGenerator\ExpressionLanguage
*/
class ExpressionLanguage extends \Symfony\Component\ExpressionLanguage\ExpressionLanguage
{
Expand All @@ -14,4 +14,4 @@ protected function registerFunctions()
// Prevent from registering constant() function by default,it could be a security issue ...
return;
}
}
}
Loading

0 comments on commit 35425bc

Please sign in to comment.