Skip to content

Commit

Permalink
Merge pull request #53 from LinioIT/feat/update-doctrine-inflector-de…
Browse files Browse the repository at this point in the history
…pendency

feat: upgrade doctrine inflector to v2
  • Loading branch information
klaussilveira authored Nov 23, 2021
2 parents e52fb3c + 72eb026 commit 972c326
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 28 deletions.
41 changes: 41 additions & 0 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: PHP Composer

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.2'

- name: Validate composer.json and composer.lock
run: composer validate --strict

- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v2
with:
path: vendor
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-php-
- name: Install dependencies
run: composer install --prefer-dist --no-progress

- name: Run linter
run: vendor/bin/php-cs-fixer fix --dry-run -v

- name: Run test suite
run: vendor/bin/phpunit --verbose
19 changes: 0 additions & 19 deletions .travis.yml

This file was deleted.

6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
"type": "library",
"license": "BSD-3-Clause",
"require": {
"php": ">=7.1",
"doctrine/inflector": "^1.0",
"ramsey/uuid": "^3.8"
"php": ">=7.2",
"ramsey/uuid": "^3.8",
"doctrine/inflector": "^2.0"
},
"require-dev": {
"phpunit/phpunit": ">=6.0",
Expand Down
5 changes: 3 additions & 2 deletions src/Instantiator/PropertyInstantiator.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Linio\Component\Input\Instantiator;

use Doctrine\Common\Inflector\Inflector;
use Doctrine\Inflector\InflectorFactory;

class PropertyInstantiator implements InstantiatorInterface
{
Expand All @@ -14,10 +14,11 @@ public function instantiate(string $class, ?array $data)
return null;
}

$inflector = InflectorFactory::create()->build();
$object = new $class();

foreach ($data as $key => $value) {
$property = Inflector::camelize($key);
$property = $inflector->camelize($key);
$object->$property = $value;
}

Expand Down
5 changes: 3 additions & 2 deletions src/Instantiator/ReflectionInstantiator.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@

namespace Linio\Component\Input\Instantiator;

use Doctrine\Common\Inflector\Inflector;
use Doctrine\Inflector\InflectorFactory;

class ReflectionInstantiator implements InstantiatorInterface
{
public function instantiate(string $class, array $data)
{
$inflector = InflectorFactory::create()->build();
$object = new $class();
$reflection = new \ReflectionClass($object);

foreach ($data as $key => $value) {
$property = $reflection->getProperty(Inflector::camelize($key));
$property = $reflection->getProperty($inflector->camelize($key));
if (!$property->isPublic()) {
$property->setAccessible(true);
}
Expand Down
5 changes: 3 additions & 2 deletions src/Instantiator/SetInstantiator.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@

namespace Linio\Component\Input\Instantiator;

use Doctrine\Common\Inflector\Inflector;
use Doctrine\Inflector\InflectorFactory;

class SetInstantiator implements InstantiatorInterface
{
public function instantiate(string $class, array $data)
{
$inflector = InflectorFactory::create()->build();
$object = new $class();

foreach ($data as $key => $value) {
$method = 'set' . Inflector::classify($key);
$method = 'set' . $inflector->classify($key);
$object->$method($value);
}

Expand Down

0 comments on commit 972c326

Please sign in to comment.