Skip to content

Commit

Permalink
Fix PHP 8.4 deprecations
Browse files Browse the repository at this point in the history
Switch to symfony/string instead of pragmarx/ia-str
  • Loading branch information
dave-redfern committed Nov 28, 2024
1 parent 104d007 commit aaa2c98
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php-version: ['8.1', '8.2', '8.3']
php-version: ['8.1', '8.2', '8.3', '8.4']

steps:
- uses: actions/checkout@v4
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

###> symfony/phpunit-bridge ###
.phpunit
.phpunit.cache
.phpunit.result.cache
/phpunit.xml
###< symfony/phpunit-bridge ###
Expand Down
4 changes: 4 additions & 0 deletions .idea/attribute-model.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions .idea/php.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
Change Log
==========

2024-11-28
----------

* fix PHP 8.4 deprecations
* switch to symfony/string instead of pragmarx/ia-str

2024-03-02
----------

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"require": {
"php": ">=8.1",
"ext-json": "*",
"pragmarx/ia-str": "^7.0"
"symfony/string": "^6.4|^7.0"
},
"require-dev": {
"phpunit/phpunit": "^10.5",
Expand Down
7 changes: 4 additions & 3 deletions src/AbstractModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use function method_exists;
use function preg_match;
use function sprintf;
use function Symfony\Component\String\u;

abstract class AbstractModel
{
Expand All @@ -26,7 +27,7 @@ public function __construct(array $attributes = [])
public function __call($method, $parameters)
{
$mutator = $this->getAttributeMutator($method);
$attribute = Str::snake($method);
$attribute = u($method)->snake()->toString();

if (array_key_exists($attribute, $this->attributes) || method_exists($this, $mutator)) {
return $this->getAttribute($attribute);
Expand Down Expand Up @@ -69,7 +70,7 @@ public function getAttributes(): array
$matches = [];

if (!in_array($method, $ignore) && preg_match('/^get(?<property>[\w\d]+)Attribute/', $method, $matches)) {
$prop = Str::snake($matches['property']);
$prop = u($matches['property'])->snake()->toString();

$attributes[$prop] = $this->{$method}($this->attributes[$prop] ?? null);
}
Expand Down Expand Up @@ -122,6 +123,6 @@ public function getAttribute(string $name): mixed

protected function getAttributeMutator(string $name): string
{
return sprintf('get%sAttribute', Str::studly($name));
return sprintf('get%sAttribute', u($name)->camel()->title()->toString());
}
}

0 comments on commit aaa2c98

Please sign in to comment.