Skip to content
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 .github/workflows/code-style.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
uses: shivammathur/setup-php@v2
with:
coverage: none
php-version: "7.1"
php-version: "8.4"
ini-values: memory_limit=-1
tools: phpcs, cs2pr
- name: Run PHP Code Sniffer
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: "7.1"
php-version: "8.4"
ini-values: memory_limit=-1
tools: composer:v2
- name: Cache dependencies
Expand Down
34 changes: 2 additions & 32 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ jobs:
strategy:
matrix:
php-version:
- "7.1"
- "7.4"
- "8.4"
steps:
Expand Down Expand Up @@ -39,41 +38,12 @@ jobs:
- name: Run PHPUnit
run: make test-coveralls
env:
PHPUNIT_VERSION: "${{ matrix.php-version == '8.4' && '11' || '07' }}"
PHPUNIT_VERSION: "${{ matrix.php-version == '8.4' && '11' || '09' }}"

- name: Upload code coverage
if: ${{ matrix.php-version == '7.1' }}
if: ${{ matrix.php-version == '7.4' }}
env:
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
composer global require php-coveralls/php-coveralls
php-coveralls --coverage_clover=build/logs/clover.xml -v

test-helpers:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install PHP
uses: shivammathur/setup-php@v2
with:
coverage: xdebug
php-version: "7.1"
ini-values: memory_limit=-1
tools: composer:v2
- name: Cache dependencies
uses: actions/cache@v4
with:
path: |
~/.composer/cache
vendor
key: "php-7.1"
restore-keys: "php-7.1"

- name: Install dependencies
run: composer install --no-interaction --no-progress

- name: Run PHPUnit
run: make test
env:
PHPUNIT_VERSION: "07-helpers"
24 changes: 24 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,29 @@
# CHANGELOG

## v4.0.0

### New requirements

Require PHP 7.4+ (older Debian distributions are now archived)

### New features

None

### Backward Incompatible Changes

Removed helper functions, use `StaticInflector` instead.

### Deprecated Features

None

### Other Changes

Updated PHPUnit to v9.6 to avoid [vulnerability](https://github.com/ICanBoogie/Inflector/security/dependabot/1).



## v3.0.2

### New requirements
Expand Down
23 changes: 5 additions & 18 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
ARG PHP_TAG=7.1-cli-buster
ARG PHP_TAG=7.4-cli-bullseye
FROM php:${PHP_TAG}

RUN <<-EOF
apt-get update
apt-get install unzip
docker-php-ext-enable opcache

if [ "$PHP_VERSION" \< "7.4" ]; then
apt-get update
apt-get install -y autoconf pkg-config
pecl channel-update pecl.php.net
pecl install xdebug-2.9.0
docker-php-ext-enable xdebug
fi
EOF

RUN <<-EOF
Expand All @@ -23,14 +17,7 @@ EOF

ENV COMPOSER_ALLOW_SUPERUSER 1

RUN <<-EOF
apt-get update
apt-get install unzip
curl -s https://raw.githubusercontent.com/composer/getcomposer.org/76a7060ccb93902cd7576b67264ad91c8a2700e2/web/installer | php -- --quiet
mv composer.phar /usr/local/bin/composer
cat <<-SHELL >> /root/.bashrc
export PATH="$HOME/.composer/vendor/bin:$PATH"
SHELL
EOF
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
ENV PATH="/root/.composer/vendor/bin:${PATH}"

RUN composer global require squizlabs/php_codesniffer
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ test-coveralls: test-dependencies
@XDEBUG_MODE=coverage $(PHPUNIT) --coverage-clover build/logs/clover.xml

.PHONY: test-container
test-container: test-container-71
test-container: test-container-74

.PHONY: test-container-71
test-container-71:
@-docker-compose run --rm app71 bash
.PHONY: test-container-74
test-container-74:
@-docker-compose run --rm app74 bash
@docker-compose down -v

.PHONY: test-container-84
Expand Down
13 changes: 1 addition & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,26 +125,15 @@ Static interfaces are also available:
```php
<?php

namespace ICanBoogie;
use ICanBoogie\StaticInflector;

# Static inflector
echo StaticInflector::pluralize('child'); // "children"
echo StaticInflector::pluralize('genou', 'fr'); // "genoux"
echo StaticInflector::singularize('lærere', 'nb'); // "lærer"
echo StaticInflector::pluralize('üçgen', 'tr'); // "üçgenler"

# Helper functions
echo pluralize('child'); // "children"
echo pluralize('genou', 'fr'); // "genoux"
echo singularize('lærere', 'nb'); // "lærer"
echo pluralize('üçgen', 'tr'); // "üçgenler"
```

> [!WARNING]
> Since v3.0 the file with the helper functions is no longer included in the
> autoload.
> You need to include the file `vendor/icanboogie/inflector/lib/helpers.php`
> in your `composer.json` if you want to continue using these functions.


## About inflections
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@
"sort-packages": true
},
"require": {
"php": ">=7.1",
"php": ">=7.4",
"ext-mbstring": "*"
},
"require-dev": {
"icanboogie/common": "^2.1",
"phpstan/phpstan": "^1.4|^2.0",
"phpunit/phpunit": "^7.5.20|^11.4"
"phpstan/phpstan": "^2.1",
"phpunit/phpunit": "^9.6.34|^11.4"
},
"conflict": {
"icanboogie/common": "<2.0"
Expand Down
8 changes: 4 additions & 4 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
---
services:
app71:
app74:
build:
context: .
args:
PHP_TAG: "7.1-cli-buster"
PHP_TAG: "7.4-cli-bullseye"
environment:
PHP_IDE_CONFIG: 'serverName=icanboogie-inflector'
PHPUNIT_VERSION: "07"
PHPUNIT_VERSION: "09"
volumes: &vol
- .:/app:delegated
- ~/.composer:/root/.composer:delegated
Expand All @@ -16,7 +16,7 @@ services:
build:
context: .
args:
PHP_TAG: "8.4.0RC4-cli-bookworm"
PHP_TAG: "8.4-cli-bookworm"
environment:
PHP_IDE_CONFIG: 'serverName=icanboogie-inflector'
PHPUNIT_VERSION: "11"
Expand Down
37 changes: 22 additions & 15 deletions lib/Inflections.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@
/**
* A representation of the inflections used by an inflector.
*
* @property-read array $plurals Rules for {@see pluralize()}.
* @property-read array $singulars Rules for {@see singularize()}.
* @property-read array $uncountables Uncountables.
* @property-read array $humans Rules for {@see humanize()}.
* @property-read array $acronyms Acronyms.
* @property-read array<string, string> $plurals Rules for {@see pluralize()}.
* @property-read array<string, string> $singulars Rules for {@see singularize()}.
* @property-read array<string, string> $uncountables Uncountables.
* @property-read array<string, string> $humans Rules for {@see humanize()}.
* @property-read array<string, string> $acronyms Acronyms.
* @property-read string $acronym_regex Acronyms regex.
*/
final class Inflections
{
/**
* @var array<string , Inflections>
*/
private static $inflections = [];
private static array $inflections = [];

/**
* Returns inflections for the specified locale.
Expand Down Expand Up @@ -52,42 +52,51 @@ public static function get(string $locale = Inflector::DEFAULT_LOCALE): Inflecti
*
* @var array<string, string> Where _key_ is a rule and _value_ a replacement.
*/
protected $plurals = [];
private array $plurals = [];

/**
* Rules for {@see singularize()}.
*
* @var array<string, string> Where _key_ is a rule and _value_ a replacement.
*/
protected $singulars = [];
private array $singulars = [];

/**
* Uncountables.
*
* @var array<string, string> Where _key_ is a word and _value_ the same word.
*/
protected $uncountables = [];
private array $uncountables = [];

/**
* Rules for {@see humanize()}.
*
* @var array<string, string> Where _key_ is a rule and _value_ a replacement.
*/
protected $humans = [];
private array $humans = [];

/**
* Acronyms.
*
* @var array<string, string> Where _key_ is a lower case version of _value_.
*/
protected $acronyms = [];
private array $acronyms = [];

/**
* Acronyms regex.
*
* @var string
*/
protected $acronym_regex = '/(?=a)b/';
private string $acronym_regex = '/(?=a)b/';

private const READERS = [
'acronyms' => true,
'acronym_regex' => true,
'plurals' => true,
'singulars' => true,
'uncountables' => true,
'humans' => true,
];

/**
* Returns the {@see $acronyms}, {@see $acronym_regex}, {@see $plurals}, {@see $singulars},
Expand All @@ -102,9 +111,7 @@ public static function get(string $locale = Inflector::DEFAULT_LOCALE): Inflecti
*/
public function __get(string $property)
{
static $readers = [ 'acronyms', 'acronym_regex', 'plurals', 'singulars', 'uncountables', 'humans' ];

if (in_array($property, $readers)) {
if (isset(self::READERS[$property])) {
return $this->$property;
}

Expand Down
9 changes: 0 additions & 9 deletions lib/InflectionsNotFound.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
<?php

/*
* This file is part of the ICanBoogie package.
*
* (c) Olivier Laviale <olivier.laviale@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace ICanBoogie;

use LogicException;
Expand Down
18 changes: 3 additions & 15 deletions lib/Inflector.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
<?php

/*
* This file is part of the ICanBoogie package.
*
* (c) Olivier Laviale <olivier.laviale@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace ICanBoogie;

use InvalidArgumentException;
Expand Down Expand Up @@ -44,7 +35,7 @@ class Inflector
/**
* @var array<string, Inflector>
*/
private static $inflectors = [];
private static array $inflectors = [];

/**
* Returns an inflector for the specified locale.
Expand All @@ -54,16 +45,13 @@ class Inflector
*/
public static function get(string $locale = self::DEFAULT_LOCALE): self
{
return self::$inflectors[$locale]
?? self::$inflectors[$locale] = new self(Inflections::get($locale));
return self::$inflectors[$locale] ??= new self(Inflections::get($locale));
}

/**
* Inflections used by the inflector.
*
* @var Inflections
*/
private $inflections;
private Inflections $inflections;

public function __construct(?Inflections $inflections = null)
{
Expand Down
4 changes: 4 additions & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,8 @@
<rule ref="PSR1.Files.SideEffects.FoundWithSymbols">
<exclude-pattern>*/tests/HelpersTest.php</exclude-pattern>
</rule>

<rule ref="Squiz.Classes.ValidClassName.NotPascalCase">
<exclude-pattern>lib/Inflections/*</exclude-pattern>
</rule>
</ruleset>
Loading