Skip to content

Commit

Permalink
Merge pull request #4 from ker0x/master
Browse files Browse the repository at this point in the history
Fix Travis build, README informations, PHPDoc Block
  • Loading branch information
TCB13 authored Sep 11, 2017
2 parents 8c7bb7b + ebc17bf commit e6934e2
Show file tree
Hide file tree
Showing 10 changed files with 101 additions and 73 deletions.
9 changes: 5 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
language: php

php:
- 7.1
- 7.0
Expand All @@ -9,11 +10,11 @@ php:

sudo: false

install: travis_retry composer install --no-interaction --prefer-source
before_install:
- composer self-update

before_script:
- travis_retry composer self-update
- travis_retry composer install --no-interaction --prefer-source
install:
- composer install --prefer-dist --no-interaction

script:
- vendor/bin/phpunit
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ in your composer.json file:
}
],
"require": {
"danielstjules/Stringy": "dev-master",
"tcb13/SubStringy": "dev-master"
"danielstjules/stringy": "^3.1",
"tcb13/substringy": "dev-master"
}
}
```
Expand Down
80 changes: 47 additions & 33 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,36 +1,50 @@
{
"name": "tcb13/substringy",
"description": "A sub string manipulation library with multibyte support that extends Stringy",
"keywords": [
"multibyte", "string", "substring", "manipulation", "utility", "methods", "utf-8",
"helpers", "utils", "utf"
],
"homepage": "https://github.com/tcb13/SubStringy",
"license": "MIT",
"authors": [
{
"name": "Tadeu Bento",
"email": "[email protected]",
"homepage": "http://www.iklive.org"
}
],
"require": {
"php": ">=5.4.0",
"ext-mbstring": "*",
"danielstjules/Stringy": "dev-master"
},
"require-dev": {
"phpunit/phpunit": "~4.0"
},
"support": {
"issues": "https://github.com/tcb13/SubStringy/issues",
"source": "https://github.com/tcb13/SubStringy/SubStringy"
},
"autoload": {
"psr-4": { "SubStringy\\": "src/" },
"files": ["src/Create.php"]
},
"autoload-dev": {
"classmap": [ "tests" ]
"name": "tcb13/substringy",
"description": "A sub string manipulation library with multibyte support that extends Stringy",
"keywords": [
"multibyte",
"string",
"substring",
"manipulation",
"utility",
"methods",
"utf-8",
"helpers",
"utils",
"utf"
],
"homepage": "https://github.com/tcb13/SubStringy",
"license": "MIT",
"authors": [
{
"name": "Tadeu Bento",
"email": "[email protected]",
"homepage": "http://www.iklive.org"
}
],
"require": {
"php": ">=5.4.0",
"ext-mbstring": "*",
"danielstjules/stringy": "^3.1"
},
"require-dev": {
"phpunit/phpunit": "~4.0"
},
"support": {
"issues": "https://github.com/tcb13/SubStringy/issues",
"source": "https://github.com/tcb13/SubStringy/SubStringy"
},
"autoload": {
"psr-4": {
"SubStringy\\": "src/"
},
"files": [
"src/Create.php"
]
},
"autoload-dev": {
"classmap": [
"tests"
]
}
}
3 changes: 2 additions & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit processIsolation="false"
<phpunit bootstrap="vendor/autoload.php"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false">
<testsuites>
Expand Down
9 changes: 5 additions & 4 deletions src/Create.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@

if (!function_exists('SubStringy\create')) {
/**
* Creates a Stringy object and returns it on success.
* Creates a SubStringy object and returns it on success.
*
* @param mixed $str Value to modify, after being cast to string
* @param string $encoding The character encoding
* @return Stringy A Stringy object
* @param mixed $str Value to modify, after being cast to string
* @param string $encoding The character encoding
*
* @return SubStringy A SubStringy object
* @throws \InvalidArgumentException if an array or object without a
* __toString method is passed as the first argument
*/
Expand Down
2 changes: 1 addition & 1 deletion src/SubStringy.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Stringy\Stringy;

class SubStringy extends Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
class SubStringy extends Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
{

use SubStringyTrait;
Expand Down
54 changes: 36 additions & 18 deletions src/SubStringyTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,88 +8,106 @@
*/
trait SubStringyTrait
{

/**
* Gets the substring after the first occurrence of a separator.
* If no match is found returns false.
*
*
* @param string $separator
*
* @return string|bool
*/
public function substringAfterFirst($separator)
{
if (($offset = $this->indexOf($separator)) === false)
if (($offset = $this->indexOf($separator)) === false) {
return false;
return static::create(mb_substr($this->str, $offset + mb_strlen($separator, $this->encoding), null, $this->encoding), $this->encoding);
}

return static::create(mb_substr($this->str, $offset + mb_strlen($separator, $this->encoding), null, $this->encoding), $this->encoding);
}

/**
* Gets the substring after the last occurrence of a separator.
* If no match is found returns false.
*
*
* @param string $separator
*
* @return string|bool
*/
public function substringAfterLast($separator)
{
if (($offset = $this->indexOfLast($separator)) === false)
if (($offset = $this->indexOfLast($separator)) === false) {
return false;
}

return static::create(mb_substr($this->str, $offset + mb_strlen($separator, $this->encoding), null, $this->encoding), $this->encoding);
}

/**
* Gets the substring before the first occurrence of a separator.
* If no match is found returns false.
*
*
* @param string $separator
*
* @return string|bool
*/
public function substringBeforeFirst($separator)
{
if (($offset = $this->indexOf($separator)) === false)
if (($offset = $this->indexOf($separator)) === false) {
return false;
}

return static::create(mb_substr($this->str, 0, $offset, $this->encoding), $this->encoding);
}

/**
* Gets the substring before the last occurrence of a separator.
* If no match is found returns false.
*
*
* @param string $separator
*
* @return string|bool
*/
public function substringBeforeLast($separator)
{
if (($offset = $this->indexOfLast($separator)) === false)
if (($offset = $this->indexOfLast($separator)) === false) {
return false;
}

return static::create(mb_substr($this->str, 0, $offset, $this->encoding), $this->encoding);
}

/**
* Extracts a string from between two substrings present on the current string
* @param string $start
* @param staing $end
*
* @param string $start
* @param string $end
*
* @return string
*/
public function substringBetween($start, $end)
{
//$this->str = " " . $this->str;
$ini = mb_stripos($this->str, $start, 0, $this->encoding);
if ($ini == 0)

if ($ini === 0) {
return "";

}

$ini += mb_strlen($start, $this->encoding);
$len = mb_stripos($this->str, $end, $ini, $this->encoding) - $ini;

return static::create(mb_substr($this->str, $ini, $len, $this->encoding), $this->encoding);
}

/**
* Count the number of substring occurrences on the current string
* @param string $substr
* Count the number of substring occurrences on the current string
*
* @param string $substr
*
* @return int
*/
public function substringCount($substr)
{
return mb_substr_count($this->str , $substr, $this->encoding);
return mb_substr_count($this->str, $substr, $this->encoding);
}
}
8 changes: 3 additions & 5 deletions tests/CommonTest.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?php

use SubStringy\SubStringy;

abstract class CommonTest extends PHPUnit_Framework_TestCase
{
/**
Expand All @@ -21,7 +19,7 @@ public function substringAfterFirstProvider()
array(' now, me is also here', 'find me now, me is also here', 'me', 'UTF-8'),
);
}

public function substringAfterLastProvider()
{
return array(
Expand All @@ -48,14 +46,14 @@ public function substringBeforeLastProvider()

public function substringBetweenProvider()
{
return array(
return array(
array(' nice ', 'hello this is a nice string', 'a', 'string', 'UTF-8'),
);
}

public function substringCountProvider()
{
return array(
return array(
array(2, 'hello how are you? are you ok?', '?', 'UTF-8'),
array(1, 'hello how are you? are you ok?', 'hello', 'UTF-8'),
);
Expand Down
2 changes: 0 additions & 2 deletions tests/CreateTest.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?php

require __DIR__ . '/../src/Create.php';

use function SubStringy\create as s;

class CreateTestCase extends PHPUnit_Framework_TestCase
Expand Down
3 changes: 0 additions & 3 deletions tests/SubStringyTest.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
<?php

require_once __DIR__ . "/../vendor/autoload.php";
require __DIR__ . '/../src/SubStringy.php';

use SubStringy\SubStringy as S;

class SubStringyTestCase extends CommonTest
Expand Down

0 comments on commit e6934e2

Please sign in to comment.