Skip to content

Commit

Permalink
Merge ddff94e into 7ff3d05
Browse files Browse the repository at this point in the history
  • Loading branch information
KavajNaruj committed Aug 8, 2018
2 parents 7ff3d05 + ddff94e commit 68923d1
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 30 deletions.
5 changes: 1 addition & 4 deletions .travis.yml
@@ -1,12 +1,9 @@
language: php

php:
- 5.3
- 5.4
- 5.5
- 5.6
- 7.0
- 7.1
- 7.2
- hhvm

matrix:
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Expand Up @@ -11,7 +11,7 @@
}
],
"require": {
"php": ">= 5.3.7"
"php": ">= 7.0"
},
"require-dev": {
"phpunit/phpunit": "~4.3",
Expand Down
2 changes: 1 addition & 1 deletion src/Prepositioner/Factory.php
Expand Up @@ -4,7 +4,7 @@

class Factory
{
public static function build($language, $escapeString = '#####')
public static function build(string $language, string $escapeString = '#####'): Prepositioner
{
$className = '\Tomaj\Prepositioner\\' . ucfirst($language) . 'Language';
if (class_exists($className)) {
Expand Down
2 changes: 1 addition & 1 deletion src/Prepositioner/LanguageInterface.php
Expand Up @@ -4,5 +4,5 @@

interface LanguageInterface
{
public function prepositions();
public function prepositions(): array;
}
21 changes: 21 additions & 0 deletions src/Prepositioner/Languages/CzechLanguage.php
@@ -0,0 +1,21 @@
<?php

namespace Tomaj\Prepositioner;

class CzechLanguage implements LanguageInterface
{
public function prepositions(): array
{
return [
/* 1 letter */
'a',
'i',
'k',
'o',
'v',
'u',
'z',
's',
];
}
}
6 changes: 3 additions & 3 deletions src/Prepositioner/Languages/SlovakLanguage.php
Expand Up @@ -4,9 +4,9 @@

class SlovakLanguage implements LanguageInterface
{
public function prepositions()
public function prepositions(): array
{
return array(
return [
/* 1 letter */
'a',
'i',
Expand Down Expand Up @@ -40,6 +40,6 @@ public function prepositions()
'spod',
'pred',
'skrz',
);
];
}
}
6 changes: 3 additions & 3 deletions src/Prepositioner/Prepositioner.php
Expand Up @@ -4,19 +4,19 @@

class Prepositioner
{
private $prepositionsArray = array();
private $prepositionsArray = [];

private $spaceCharacter = "&nbsp;";

private $escapeString;

public function __construct($prepositionsArray, $escapeString = '#####')
public function __construct(array $prepositionsArray, string $escapeString = '#####')
{
$this->prepositionsArray = $prepositionsArray;
$this->escapeString = $escapeString;
}

public function formatText($text)
public function formatText(string $text)
{
if (empty($this->prepositionsArray)) {
return $text;
Expand Down
1 change: 0 additions & 1 deletion tests/PrepositionerFactoryTest.php
Expand Up @@ -4,7 +4,6 @@
require dirname(__FILE__) . '/TestLanguage.php';

use Tomaj\Prepositioner\Factory;
use Tomaj\Prepositioner\LanguageInterface;

class PrepositionerFactoryTest extends PHPUnit_Framework_TestCase
{
Expand Down
28 changes: 14 additions & 14 deletions tests/PrepositionerTest.php
Expand Up @@ -8,71 +8,71 @@ class PrepositionerTest extends PHPUnit_Framework_TestCase
{
public function testBasicFormat()
{
$words = array('a', 'asdf', 'vd');
$words = ['a', 'asdf', 'vd'];
$prepositioner = new Prepositioner($words);
$input = "dsfoihdf s asd a sdfds asdf asd";
$this->assertEquals("dsfoihdf s asd a&nbsp;sdfds asdf&nbsp;asd", $prepositioner->formatText($input));
}

public function testInWordReplace()
{
$words = array('a');
$words = ['a'];
$prepositioner = new Prepositioner($words);
$input = "dsfdsfa dfsdg";
$this->assertEquals("dsfdsfa dfsdg", $prepositioner->formatText($input));
}

public function testFirstWord()
{
$words = array('a');
$words = ['a'];
$prepositioner = new Prepositioner($words);
$input = "a asfs a asfd";
$this->assertEquals("a&nbsp;asfs a&nbsp;asfd", $prepositioner->formatText($input));
}

public function testLastWord()
{
$words = array('a');
$words = ['a'];
$prepositioner = new Prepositioner($words);
$input = "asfd a";
$this->assertEquals("asfd a", $prepositioner->formatText($input));
}

public function testSimplePreposition()
{
$words = array('a');
$words = ['a'];
$prepositioner = new Prepositioner($words);
$input = "a";
$this->assertEquals("a", $prepositioner->formatText($input));
}

public function testUpperLowerCase()
{
$words = array('a', 'AsD', 'C', 'EE');
$words = ['a', 'AsD', 'C', 'EE'];
$prepositioner = new Prepositioner($words);
$input = "A acd asd fef c xxx Ee grgr";
$this->assertEquals("A&nbsp;acd asd&nbsp;fef c&nbsp;xxx Ee&nbsp;grgr", $prepositioner->formatText($input));
}

public function testMultipleSpaces()
{
$words = array('a');
$words = ['a'];
$prepositioner = new Prepositioner($words);
$input = "asd a asd";
$this->assertEquals("asd a&nbsp;asd", $prepositioner->formatText($input));
}

public function testHtmlTextElementReplace()
{
$words = array('a');
$words = ['a'];
$prepositioner = new Prepositioner($words);
$input = "asd a fs <a>sa a sd</a>";
$this->assertEquals("asd a&nbsp;fs <a>sa a&nbsp;sd</a>", $prepositioner->formatText($input));
}

public function testHtmlContentDoesntReplace()
{
$words = array('a');
$words = ['a'];
$prepositioner = new Prepositioner($words);
$input = "asd a fs <p a sad>sdasd</p>";
$this->assertEquals("asd a&nbsp;fs <p a sad>sdasd</p>", $prepositioner->formatText($input));
Expand All @@ -83,7 +83,7 @@ public function testHtmlContentDoesntReplace()

public function testSpecialCharacters()
{
$words = array('a');
$words = ['a'];
$prepositioner = new Prepositioner($words);
$input = "asd a\t\tx a\nasdcdcd a<br/>asd";
$this->assertEquals("asd a&nbsp;x a&nbsp;asdcdcd a<br/>asd", $prepositioner->formatText($input));
Expand All @@ -94,31 +94,31 @@ public function testSpecialCharacters()

public function testFirstWordInTag()
{
$words = array('a');
$words = ['a'];
$prepositioner = new Prepositioner($words);
$input = "<p>a bout</p>";
$this->assertEquals("<p>a&nbsp;bout</p>", $prepositioner->formatText($input));
}

public function testDisablePrepositionsReplace()
{
$words = array('a', 'b');
$words = ['a', 'b'];
$prepositioner = new Prepositioner($words, '#####');
$input = "asd #####a##### asdsa b cc a asd s b";
$this->assertEquals("asd a asdsa b&nbsp;cc a&nbsp;asd s b", $prepositioner->formatText($input));
}

public function testMorePreposition()
{
$words = array('a', 'b', 'c');
$words = ['a', 'b', 'c'];
$prepositioner = new Prepositioner($words);
$input = "asd a c b asd b c";
$this->assertEquals("asd a&nbsp;c&nbsp;b&nbsp;asd b&nbsp;c", $prepositioner->formatText($input));
}

public function testMultiplePreposition()
{
$words = array('a', 'b', 'c');
$words = ['a', 'b', 'c'];
$prepositioner = new Prepositioner($words);
$input = "a b c a b b c";
$this->assertEquals("a&nbsp;b&nbsp;c&nbsp;a&nbsp;b&nbsp;b&nbsp;c", $prepositioner->formatText($input));
Expand Down
4 changes: 2 additions & 2 deletions tests/TestLanguage.php
Expand Up @@ -5,8 +5,8 @@
// This need to be removed but i need to change factory behaviour
class TestLanguage implements LanguageInterface
{
public function prepositions()
public function prepositions(): array
{
return array('a', 'b');
return ['a', 'b'];
}
}

0 comments on commit 68923d1

Please sign in to comment.