Skip to content

Commit

Permalink
Merge pull request #30 from heiglandreas/feature/adaptToPSR4-2
Browse files Browse the repository at this point in the history
Feature/adapt to psr-4
  • Loading branch information
heiglandreas committed Jan 24, 2017
2 parents d50ccdb + d5ee9ca commit fefc6cc
Show file tree
Hide file tree
Showing 130 changed files with 327 additions and 345 deletions.
1 change: 0 additions & 1 deletion .coveralls.yml
@@ -1,3 +1,2 @@
coverage_clover: clover.xml
json_path: coveralls-upload.json
src_dir: src
12 changes: 7 additions & 5 deletions .php_cs
@@ -1,5 +1,5 @@
<?php
$finder = Symfony\CS\Finder\DefaultFinder::create()
$finder = PhpCsFixer\Finder::create()
->in('src')
->in('tests')
->notPath('TestAsset')
Expand All @@ -10,7 +10,9 @@ $finder = Symfony\CS\Finder\DefaultFinder::create()
return false;
}
});
$config = Symfony\CS\Config\Config::create();
$config->level('psr2');
$config->finder($finder);
return $config;

return PhpCsFixer\Config::create()
->setRules([
'@PSR2' => true,
])
->setFinder($finder);
22 changes: 12 additions & 10 deletions .travis.yml
Expand Up @@ -8,37 +8,39 @@ matrix:
allow_failures:
- php: 5.3
- php: 5.4
- php: 5.5
- php: nightly
include:
- php: 5.3
- php: 5.4
- php: 5.5
- php: 5.6
env:
- DEPS=lowest
- php: 5.5
- php: 5.6
env:
- DEPS=locked
- CHECK_CS=true
- php: 5.5
- php: 5.6
env:
- DEPS=latest
- php: 5.6
- php: 7.0
env:
- DEPS=lowest
- php: 5.6
- php: 7.0
env:
- DEPS=locked
- TEST_COVERAGE=true
- php: 5.6
- php: 7.0
env:
- DEPS=latest
- php: 7
- php: 7.1
env:
- DEPS=lowest
- php: 7
- php: 7.1
env:
- DEPS=locked
- php: 7
- TEST_COVERAGE=true
- CHECK_CS=true
- php: 7.1
env:
- DEPS=latest
- php: hhvm
Expand Down
19 changes: 14 additions & 5 deletions composer.json
Expand Up @@ -19,11 +19,10 @@
},
"require-dev" : {
"mockery/mockery" : "^0.9",
"phpunit/phpunit": "^4.8||^5.3",
"fabpot/php-cs-fixer": "^1.7"
"phpunit/phpunit": "^4.8||^5.3"
},
"autoload" : {
"psr-0" : {
"psr-4" : {
"Org\\Heigl\\Hyphenator\\" : "src"
}
},
Expand All @@ -38,8 +37,18 @@
"@test"
],
"upload-coverage": "coveralls -v",
"cs-check": "php-cs-fixer --version && php-cs-fixer fix -v --diff --dry-run",
"cs-fix": "php-cs-fixer fix -v",
"cs-download" : [
"if [ ! -e php-cs-fixer ] ; then curl -o php-cs-fixer -L `curl -s https://api.github.com/repos/FriendsOfPHP/PHP-CS-Fixer/releases | grep browser_download_url | head -n 1 | cut -d '\"' -f 4`; fi",
"chmod 755 php-cs-fixer"
],
"cs-check": [
"@cs-download",
"./php-cs-fixer --version && ./php-cs-fixer fix -v --diff --dry-run"
],
"cs-fix": [
"@cs-download",
"./php-cs-fixer fix -v"
],
"test": "phpunit",
"test-coverage": "phpunit --coverage-clover clover.xml"
}
Expand Down
File renamed without changes.
Expand Up @@ -53,7 +53,7 @@ class Dictionary
*
* @var array $_dictionary
*/
protected $_dictionary = array ();
protected $_dictionary = array();

/**
* Where to look for the basic files.
Expand Down Expand Up @@ -81,7 +81,6 @@ public static function setFileLocation($fileLocation)
*/
public function __construct()
{

}

/**
Expand Down Expand Up @@ -111,10 +110,10 @@ public function load($locale)
$locale = $this->_unifyLocale($locale);
$file = self::$_fileLocation . DIRECTORY_SEPARATOR . $locale . '.ini';
$this->_dictionary = array();
if ( ! file_exists(realpath($file)) ) {
if (! file_exists(realpath($file))) {
return $this;
}
foreach ( parse_ini_file($file) as $key => $val ) {
foreach (parse_ini_file($file) as $key => $val) {
$this->_dictionary[str_replace('@:', '', $key)] = $val;
}

Expand All @@ -133,7 +132,7 @@ public static function parseFile($locale)
{
$path = self::$_fileLocation . DIRECTORY_SEPARATOR;
$file = $path . 'hyph_' . $locale . '.dic';
if ( ! file_Exists($file) ) {
if (! file_Exists($file)) {
throw new \Org\Heigl\Hyphenator\Exception\PathNotFoundException('The given Path does not exist');
}

Expand All @@ -142,25 +141,25 @@ public static function parseFile($locale)
if (0===strpos($source, 'ISO8859')) {
$source = str_Replace('ISO8859', 'ISO-8859', $source);
}
unset ($items[0]);
unset($items[0]);
$fh = fopen($path . $locale . '.ini', 'w+');
foreach ($items as $item) {
// Remove comment-lines starting with '#' or '%'.
if ( in_array(mb_substr($item, 0, 1), array('#', '%')) ) {
if (in_array(mb_substr($item, 0, 1), array('#', '%'))) {
continue;
}
// Ignore empty lines.
if ( '' == trim($item) ) {
if ('' == trim($item)) {
continue;
}
// Remove all Upper-case items as they are OOo-specific
if ($item === mb_strtoupper($item) ) {
if ($item === mb_strtoupper($item)) {
continue;
}
// Ignore lines containing an '=' sign as these are specific
// instructions for non-standard-hyphenations. These will be
// implemented later.
if ( false !== mb_strpos($item, '=') ) {
if (false !== mb_strpos($item, '=')) {
continue;
}
$item = mb_convert_Encoding($item, 'UTF-8', $source);
Expand All @@ -182,13 +181,13 @@ public static function parseFile($locale)
*/
public function getPatternsForWord($word)
{
$return = array ();
$return = array();
$word = '.' . $word . '.';
$strlen = mb_strlen($word);
for ($i = 0; $i <= $strlen; $i ++) {
for ( $j = 2; $j <= ($strlen-$i); $j++ ) {
for ($j = 2; $j <= ($strlen-$i); $j++) {
$substr = mb_substr($word, $i, $j);
if ( ! isset($this->_dictionary[$substr]) ) {
if (! isset($this->_dictionary[$substr])) {
continue;
}
$return[$substr] = $this->_dictionary[$substr];
Expand All @@ -206,7 +205,7 @@ public function getPatternsForWord($word)
*
* @return \Org\Heigl\Hyphenator\Dictionary\Dictionary
*/
public function addPAttern( $string, $pattern)
public function addPAttern($string, $pattern)
{
$this->_dictionary[$string] = $pattern;

Expand All @@ -230,10 +229,10 @@ public function addPAttern( $string, $pattern)
*/
protected function _unifyLocale($locale)
{
if ( 2 == strlen($locale) ) {
if (2 == strlen($locale)) {
return strtolower($locale);
}
if ( preg_match('/([a-zA-Z]{2})[^a-zA-Z]+([a-zA-Z]{2})/i', $locale, $result) ) {
if (preg_match('/([a-zA-Z]{2})[^a-zA-Z]+([a-zA-Z]{2})/i', $locale, $result)) {
return strtolower($result[1]) . '_' . strtoupper($result[2]);
}

Expand Down
Expand Up @@ -53,7 +53,7 @@ class DictionaryRegistry implements \Iterator, \Countable
*
* @var Dictionary[] $_registry
*/
protected $_registry = array ();
protected $_registry = array();

/**
* Add an item to the registry.
Expand All @@ -64,7 +64,7 @@ class DictionaryRegistry implements \Iterator, \Countable
*/
public function add(Dictionary $dict)
{
if ( ! in_array($dict, $this->_registry)) {
if (! in_array($dict, $this->_registry)) {
$this->_registry[] = $dict;
}

Expand All @@ -80,7 +80,7 @@ public function add(Dictionary $dict)
*/
public function getDictionaryWithKey($key)
{
if ( array_key_exists($key, $this->_registry)) {
if (array_key_exists($key, $this->_registry)) {
return $this->_registry[$key];
}

Expand All @@ -96,7 +96,7 @@ public function getDictionaryWithKey($key)
*/
public function getHyphenationPattterns($word)
{
$pattern = array ();
$pattern = array();
foreach ($this as $dictionary) {
$pattern = array_merge($pattern, $dictionary->getPatternsForWord($word));
}
Expand Down Expand Up @@ -173,7 +173,7 @@ public function next()
*/
public function valid()
{
if ( false === current($this->_registry)) {
if (false === current($this->_registry)) {
return false;
}

Expand Down
Expand Up @@ -75,15 +75,15 @@ public function setPattern($pattern)
$strlen = mb_strlen($item);
$return = array();
for ($i = 0; $i < $strlen; $i++) {
if ( ( ( $i ) <= $strlen ) && preg_match('/[0-9]/u', mb_substr($item, $i, 1)) ) {
if ((($i) <= $strlen) && preg_match('/[0-9]/u', mb_substr($item, $i, 1))) {
$this->_pattern .= mb_substr($item, $i, 1);
$i++;
} else {
$this->_pattern .= '0';
}
}
$this->_text = preg_replace(array('/[0-9]/u','/\'/u'), array('','\\’'), $item);
if ( strlen($this->_pattern) == mb_strlen($this->_text) ) {
if (strlen($this->_pattern) == mb_strlen($this->_text)) {
$this->_pattern .= '0';
}

Expand Down
File renamed without changes.
Expand Up @@ -46,8 +46,6 @@
* @link http://github.com/heiglandreas/Hyphenator
* @since 02.11.2011
*/
class InvalidArgumentException
extends \InvalidArgumentException
implements \Org\Heigl\Hyphenator\Exception
class InvalidArgumentException extends \InvalidArgumentException implements \Org\Heigl\Hyphenator\Exception
{
}
Expand Up @@ -46,8 +46,6 @@
* @link http://github.com/heiglandreas/Hyphenator
* @since 02.11.2011
*/
class NoPatternSetException
extends \InvalidArgumentException
implements \Org\Heigl\Hyphenator\Exception
class NoPatternSetException extends \InvalidArgumentException implements \Org\Heigl\Hyphenator\Exception
{
}
Expand Up @@ -47,8 +47,6 @@
* @link http://github.com/heiglandreas/Hyphenator
* @since 02.11.2011
*/
class PathNotDirException
extends \InvalidArgumentException
implements \Org\Heigl\Hyphenator\Exception
class PathNotDirException extends \InvalidArgumentException implements \Org\Heigl\Hyphenator\Exception
{
}
Expand Up @@ -47,8 +47,6 @@
* @link http://github.com/heiglandreas/Hyphenator
* @since 02.11.2011
*/
class PathNotFoundException
extends \InvalidArgumentException
implements \Org\Heigl\Hyphenator\Exception
class PathNotFoundException extends \InvalidArgumentException implements \Org\Heigl\Hyphenator\Exception
{
}
File renamed without changes.
File renamed without changes.
Expand Up @@ -54,7 +54,7 @@ class FilterRegistry implements \Iterator, \Countable
*
* @var \Org\Heigl\Hyphenator\Filter\Filter[] $_registry
*/
protected $_registry = array ();
protected $_registry = array();

/**
* Add an item to the registry
Expand All @@ -66,7 +66,7 @@ class FilterRegistry implements \Iterator, \Countable
*/
public function add(Filter $filter)
{
if ( ! in_array($filter, $this->_registry)) {
if (! in_array($filter, $this->_registry)) {
$this->_registry[] = $filter;
}

Expand All @@ -82,7 +82,7 @@ public function add(Filter $filter)
*/
public function getFilterWithKey($key)
{
if ( array_key_exists($key, $this->_registry)) {
if (array_key_exists($key, $this->_registry)) {
return $this->_registry[$key];
}

Expand All @@ -96,7 +96,7 @@ public function getFilterWithKey($key)
*/
public function cleanup()
{
$this->_registry = array ();
$this->_registry = array();

return $this;
}
Expand Down Expand Up @@ -203,11 +203,10 @@ public function next()
*/
public function valid()
{
if ( false === current($this->_registry)) {
if (false === current($this->_registry)) {
return false;
}

return true;
}

}
Expand Up @@ -73,16 +73,16 @@ public function run(t\TokenRegistry $tokens)
$result = array();
for ($i = 1; $i <= $length; $i++) {
$currPattern = mb_substr($pattern, $i, 1);
if ( $i < $this->_options->getLeftMin() ) {
if ($i < $this->_options->getLeftMin()) {
continue;
}
if ( $i > $length - $this->_options->getRightMin() ) {
if ($i > $length - $this->_options->getRightMin()) {
continue;
}
if (0 == $currPattern) {
continue;
}
if ( 0 === (int) $currPattern % 2 ) {
if (0 === (int) $currPattern % 2) {
continue;
}
$start = mb_substr($string, 0, $i);
Expand Down

0 comments on commit fefc6cc

Please sign in to comment.