Skip to content

Commit

Permalink
src: use strict types, return types, use implode
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed Feb 6, 2017
1 parent 86d4504 commit 1519a51
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 111 deletions.
43 changes: 14 additions & 29 deletions src/RegExp.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);

namespace Gherkins\RegExpBuilderPHP;

Expand Down Expand Up @@ -37,26 +37,17 @@ public function __construct($expr, $flags, $pregMatchFlags = null)
}
}

/**
* @return String
*/
public function __toString()
public function __toString() : string
{
return $this->getExpression();
}

/**
* @return String
*/
public function getExpression()
public function getExpression() : string
{
return $this->_expr;
}

/**
* @return String
*/
public function getFlags()
public function getFlags() : string
{
return $this->_flags;
}
Expand All @@ -65,36 +56,31 @@ public function getFlags()
* alias for matches
*
* @deprecated
* @param $string
* @return bool
*/
public function test($string)
public function test(string $string) : bool
{
return $this->matches($string);
}

/**
* check string w/ preg_match
*
* @param $string
* @return bool
*/
public function matches($string)
public function matches(string $string) : bool
{
$matches = array();
$matches = [];

return (bool)call_user_func_array(
$this->_method,
array(
[
sprintf("/%s/%s", $this->_expr, $this->_flags),
$string,
&$matches,
$this->_pregMatchFlags ?: null,
)
]
);
}

public function exec($haystack)
public function exec($haystack) : array
{
return $this->findIn($haystack);
}
Expand All @@ -103,19 +89,18 @@ public function exec($haystack)
* execute preg_match, return matches
*
* @param $haystack
* @return array
*/
public function findIn($haystack)
public function findIn($haystack) : array
{
$matches = array();
$matches = [];
call_user_func_array(
$this->_method,
array(
[
sprintf("/%s/%s", $this->_expr, $this->_flags),
$haystack,
&$matches,
$this->_pregMatchFlags ?: null,
)
]
);

if (!isset($matches[1]) && isset($matches[0]) && is_array($matches[0])) {
Expand Down
Loading

0 comments on commit 1519a51

Please sign in to comment.