From 8419369f3b1560672875f925fce7da0f59573966 Mon Sep 17 00:00:00 2001 From: Lucas Michot Date: Sat, 26 Dec 2015 05:58:00 +0100 Subject: [PATCH] Add some imports --- src/StaticStringy.php | 12 +++++++++--- src/Stringy.php | 24 ++++++++++++++++-------- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/src/StaticStringy.php b/src/StaticStringy.php index 3ae58e9..f89b18d 100644 --- a/src/StaticStringy.php +++ b/src/StaticStringy.php @@ -2,6 +2,10 @@ namespace Stringy; +use BadMethodCallException; +use ReflectionClass; +use ReflectionMethod; + /** * Class StaticStringy * @@ -107,12 +111,14 @@ class StaticStringy * @param mixed[] $arguments * * @return Stringy + * + * @throws \BadMethodCallException */ public static function __callStatic($name, $arguments) { if (!static::$methodArgs) { - $stringyClass = new \ReflectionClass('Stringy\Stringy'); - $methods = $stringyClass->getMethods(\ReflectionMethod::IS_PUBLIC); + $stringyClass = new ReflectionClass('Stringy\Stringy'); + $methods = $stringyClass->getMethods(ReflectionMethod::IS_PUBLIC); foreach ($methods as $method) { $params = $method->getNumberOfParameters() + 2; @@ -121,7 +127,7 @@ class StaticStringy } if (!isset(static::$methodArgs[$name])) { - throw new \BadMethodCallException($name . ' is not a valid method'); + throw new BadMethodCallException($name . ' is not a valid method'); } $numArgs = count($arguments); diff --git a/src/Stringy.php b/src/Stringy.php index 8e3cee3..41ab468 100644 --- a/src/Stringy.php +++ b/src/Stringy.php @@ -2,7 +2,15 @@ namespace Stringy; -class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess +use ArrayAccess; +use ArrayIterator; +use Countable; +use Exception; +use InvalidArgumentException; +use IteratorAggregate; +use OutOfBoundsException; + +class Stringy implements Countable, IteratorAggregate, ArrayAccess { /** * An instance's string. @@ -34,11 +42,11 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess public function __construct($str = '', $encoding = null) { if (is_array($str)) { - throw new \InvalidArgumentException( + throw new InvalidArgumentException( 'Passed value cannot be an array' ); } elseif (is_object($str) && !method_exists($str, '__toString')) { - throw new \InvalidArgumentException( + throw new InvalidArgumentException( 'Passed object must have a __toString method' ); } @@ -421,7 +429,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess */ public function getIterator() { - return new \ArrayIterator($this->chars()); + return new ArrayIterator($this->chars()); } /** @@ -846,7 +854,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess $length = $this->length(); if (($offset >= 0 && $length <= $offset) || $length < abs($offset)) { - throw new \OutOfBoundsException('No character exists at the index'); + throw new OutOfBoundsException('No character exists at the index'); } return mb_substr($this->str, $offset, 1, $this->encoding); @@ -863,7 +871,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess public function offsetSet($offset, $value) { // Stringy is immutable, cannot directly set char - throw new \Exception('Stringy object is immutable, cannot modify char'); + throw new Exception('Stringy object is immutable, cannot modify char'); } /** @@ -876,7 +884,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess public function offsetUnset($offset) { // Don't allow directly modifying the string - throw new \Exception('Stringy object is immutable, cannot unset char'); + throw new Exception('Stringy object is immutable, cannot unset char'); } /** @@ -896,7 +904,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess public function pad($length, $padStr = ' ', $padType = 'right') { if (!in_array($padType, array('left', 'right', 'both'))) { - throw new \InvalidArgumentException('Pad expects $padType ' . + throw new InvalidArgumentException('Pad expects $padType ' . "to be one of 'left', 'right' or 'both'"); }