Skip to content

Commit

Permalink
Fic PHP 7 compatibility
Browse files Browse the repository at this point in the history
Compatibility:
- Fix PHP 7.2 deprecations

Fixes:
- Add missing dev requirements
  • Loading branch information
MisatoTremor committed Jan 21, 2018
1 parent 19bdb3a commit 61c63b1
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 50 deletions.
11 changes: 11 additions & 0 deletions .php_cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

return PhpCsFixer\Config::create()
->setRules(
[
'@Symfony' => true,
'ordered_imports' => true,
]
)
->setUsingCache(true)
->setCacheFile(__DIR__.'/.php_cs.cache');
23 changes: 19 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,25 @@
language: php

php:
- 5.3
- 5.4
matrix:
include:
- php: 5.3
dist: precise
- php: 5.4
- php: 5.5
- php: 5.6
- php: 7.0
- php: 7.1
- php: 7.2

before_script: composer install --dev
before_install:
- |
# php.ini configuration
INI=~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini
phpenv config-rm xdebug.ini || echo "xdebug not available"
echo memory_limit = -1 >> $INI
install:
- composer install --no-interaction --prefer-dist

notifications:
email: joris.w.dewit@gmail.com
15 changes: 6 additions & 9 deletions DependencyInjection/AvroCaseExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,23 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Avro\CaseBundle\DependencyInjection;

use Symfony\Component\DependencyInjection\Alias;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
use Symfony\Component\Config\Definition\Processor;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;

/**
* Process bundle configuration
* Process bundle configuration.
*
* @author Joris de Wit <joris.w.dewit@gmail.com>
*/
class AvroCaseExtension extends Extension
{
/**
* Load bundle config
* Load bundle config.
*
* @param array $configs Config array
* @param ContainerBuilder $container The container builder
Expand All @@ -32,7 +30,7 @@ public function load(array $configs, ContainerBuilder $container)
$processor = new Processor();
$configuration = new Configuration();

$config = $processor->process($configuration->getConfigTree(), $configs);
$config = $processor->processConfiguration($configuration, $configs);

$loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));

Expand All @@ -43,4 +41,3 @@ public function load(array $configs, ContainerBuilder $container)
}
}
}

16 changes: 6 additions & 10 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,23 @@
namespace Avro\CaseBundle\DependencyInjection;

use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\Config\Definition\ConfigurationInterface;
use Symfony\Component\Config\Definition\NodeInterface;

/**
* This is the class that validates and merges configuration from your app/config files
*/
class Configuration
class Configuration implements ConfigurationInterface
{
/**
* Generates the configuration tree.
*
* @return NodeInterface
*/
public function getConfigTree()
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$treeBuilder->root('avro_case', 'array')
->children()
->booleanNode('use_twig')->defaultValue(true)->cannotBeEmpty()->end()
->booleanNode('use_twig')->defaultValue(true)->end()
->end()
->end();

return $treeBuilder->buildTree();
return $treeBuilder;
}
}
94 changes: 70 additions & 24 deletions Util/CaseConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@
namespace Avro\CaseBundle\Util;

/**
* Convert strings into different case formats
* Convert strings into different case formats.
*
* @author Joris.w.dewit <joris.w.dewit@gmail.com>
*
*/
class CaseConverter
{
/**
* Converts a string into underscore format (e.g. first_name)
* Converts a string into underscore format (e.g. first_name).
*
* @param string|array $input String
*
Expand All @@ -37,7 +36,7 @@ public function toUnderscoreCase($input)
}

/**
* Converts a string into underscore format (e.g. first_name)
* Converts a string into underscore format (e.g. first_name).
*
* @param string|array $input String
*
Expand All @@ -48,7 +47,13 @@ private function convertToUnderscoreCase($input)
$input = trim(lcfirst($input));

// camel case
$input = preg_replace_callback('/([A-Z])/', create_function('$c', 'return "_" . strtolower($c[1]);'), $input);
$input = preg_replace_callback(
'/([A-Z])/',
function ($c) {
return '_'.strtolower($c[1]);
},
$input
);

// title case
$input = str_replace(' ', '', $input);
Expand All @@ -57,7 +62,7 @@ private function convertToUnderscoreCase($input)
}

/**
* Converts a string or array into title format (e.g. First Name)
* Converts a string or array into title format (e.g. First Name).
*
* @param string|array $input String
*
Expand All @@ -78,7 +83,7 @@ public function toTitleCase($input)
}

/**
* Converts a string into title format (e.g. First Name)
* Converts a string into title format (e.g. First Name).
*
* @param string $input String
*
Expand All @@ -89,19 +94,37 @@ public function convertToTitleCase($input)
$input = ucfirst($input);

// camelCase
$input = preg_replace_callback('/([A-Z])/', create_function('$c', 'return " " . ucfirst($c[1]);'), $input);
$input = preg_replace_callback(
'/([A-Z])/',
function ($c) {
return ' '.ucfirst($c[1]);
},
$input
);

// lowercase title
$input = preg_replace_callback('/ ([a-z])/', create_function('$c', 'return " " . ucfirst($c[1]);'), $input);
$input = preg_replace_callback(
'/ ([a-z])/',
function ($c) {
return ' '.ucfirst($c[1]);
},
$input
);

// underscore
$input = preg_replace_callback('/_([a-z])/', create_function('$c', 'return " " . strtoupper($c[1]);'), $input);
$input = preg_replace_callback(
'/_([a-z])/',
function ($c) {
return ' '.strtoupper($c[1]);
},
$input
);

return trim(preg_replace('/\s+/', ' ', $input));
}

/**
* Converts a string to camel case format (e.g. firstName)
* Converts a string to camel case format (e.g. firstName).
*
* @param string|array $input String or array argument
*
Expand All @@ -122,7 +145,7 @@ public function toCamelCase($input)
}

/**
* Convert a string to camel case
* Convert a string to camel case.
*
* @param string $input Variable to convert
*
Expand All @@ -133,18 +156,30 @@ private function convertToCamelCase($input)
$input = lcfirst($input);

// underscore
$input = preg_replace_callback('/_([a-z])/', create_function('$c', 'return strtoupper($c[1]);'), $input);
$input = preg_replace_callback(
'/_([a-z])/',
function ($c) {
return strtoupper($c[1]);
},
$input
);

// title
$input = preg_replace_callback('/ ([a-z])/', create_function('$c', 'return strtoupper($c[1]);'), $input);
$input = preg_replace_callback(
'/ ([a-z])/',
function ($c) {
return strtoupper($c[1]);
},
$input
);

$input = str_replace(' ', '', $input);

return $input;
}

/**
* Converts a string to pascal case format (e.g. FirstName)
* Converts a string to pascal case format (e.g. FirstName).
*
* @param string|array $input String or array argument
*
Expand All @@ -165,7 +200,7 @@ public function toPascalCase($input)
}

/**
* Converts a string to pascal case format (e.g. FirstName)
* Converts a string to pascal case format (e.g. FirstName).
*
* @param string|array $input String
*
Expand All @@ -176,18 +211,30 @@ private function convertToPascalCase($input)
$input = ucfirst($input);

// underscore
$input = preg_replace_callback('/_([a-z])/', create_function('$c', 'return strtoupper($c[1]);'), $input);
$input = preg_replace_callback(
'/_([a-z])/',
function ($c) {
return strtoupper($c[1]);
},
$input
);

// title
$input = preg_replace_callback('/ ([a-z])/', create_function('$c', 'return strtoupper($c[1]);'), $input);
$input = preg_replace_callback(
'/ ([a-z])/',
function ($c) {
return strtoupper($c[1]);
},
$input
);

$input = str_replace(' ', '', $input);

return $input;
}

/**
* Convert string
* Convert string.
*
* @param string|array $input Input argument as string or array
* @param string|array $format Desired Case format
Expand All @@ -196,7 +243,7 @@ private function convertToPascalCase($input)
*/
public function convert($input, $format = 'camel')
{
switch($format) {
switch ($format) {
case 'camel':
return $this->toCamelCase($input);
break;
Expand All @@ -213,7 +260,7 @@ public function convert($input, $format = 'camel')
}

/**
* Get the format of a string
* Get the format of a string.
*
* @param string $input The input string
*
Expand All @@ -223,13 +270,12 @@ public function getFormat($input)
{
if (strpos($input, ' ')) {
return 'title';
} else if (strpos($input, '_')) {
} elseif (strpos($input, '_')) {
return 'underscore';
} else if ($input{0} === strtoupper($input{0})) {
} elseif ($input[0] === strtoupper($input[0])) {
return 'pascal';
} else {
return 'camel';
}
}

}
16 changes: 13 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,22 @@
{
"name": "Joris de Wit",
"email": "joris.w.dewit@gmail.com"
}
}
],
"minimum-stability": "dev",
"extra": {
"branch-alias": {
"dev-master": "0.2-dev"
}
},
"require": {
"php": ">=5.3.2",
"twig/twig": "^1.12.0"
"php": "^5.5.9|>=7.0.8",
"twig/twig": "^1.12.0"
},
"require-dev": {
"phpunit/phpunit": "~4.0|~5.0",
"symfony/config": "~2.8|~3.0|~4.0",
"symfony/dependency-injection": "~2.8|~3.0|~4.0"
},
"autoload": {
"psr-4": { "Avro\\CaseBundle\\": "" }
Expand Down

0 comments on commit 61c63b1

Please sign in to comment.