Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Implement part of request #14888: Improve PHPCS results

git-svn-id: http://svn.php.net/repository/pear/packages/Image_Color2/trunk@295020 c90b9560-bf6c-de11-be94-00142212c4b1
  • Loading branch information...
commit d1bc8ef985bb13c49f6ff1342f73665e853fc439 1 parent 16c5a6e
@cweiske cweiske authored
Showing with 101 additions and 86 deletions.
  1. +76 −66 Image/Color2.php
  2. +25 −20 Image/Color2/Model.php
View
142 Image/Color2.php
@@ -6,13 +6,13 @@
*
* PHP version 5
*
- * @category Image
- * @package Image_Color2
- * @author andrew morton <drewish@katherinehouse.com>
- * @copyright 2005
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
- * @version $Id$
- * @link http://pear.php.net/package/Image_Color2
+ * @category Image
+ * @package Image_Color2
+ * @author andrew morton <drewish@katherinehouse.com>
+ * @copyright 2005 Andrew Morton
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version SVN: $Id$
+ * @link http://pear.php.net/package/Image_Color2
*/
/**
@@ -71,36 +71,37 @@
* A large portion of the code for this package was derived from the work of
* Jason Lotito and the other contributors to Image_Color.
*
- * @category Image
- * @package Image_Color2
- * @author andrew morton <drewish@katherinehouse.com>
- * @copyright 2005
- * @license http://opensource.org/licenses/lgpl-license.php
- * GNU Lesser General Public License, Version 2.1
- * @version Release: 0.1.2
- * @link http://pear.php.net/package/Image_Color2
- * @see Image_Color
- * @todo Figure out a clean way to support alpha channels. This class
- * will preserve them but as soon as you call a color model for
- * conversion they'll be discarded. I think this class will need
- * to maintain a separate variable for the alpha channel it really
- * seems independent of the color model. 50% red would be the same
- * no mater how you represent it.
+ * @category Image
+ * @package Image_Color2
+ * @author andrew morton <drewish@katherinehouse.com>
+ * @copyright 2005 Andrew Mortin
+ * @license http://opensource.org/licenses/lgpl-license.php
+ * GNU Lesser General Public License, Version 2.1
+ * @version Release: 0.1.2
+ * @link http://pear.php.net/package/Image_Color2
+ * @see Image_Color
+ * @todo Figure out a clean way to support alpha channels. This class
+ * will preserve them but as soon as you call a color model for
+ * conversion they'll be discarded. I think this class will need
+ * to maintain a separate variable for the alpha channel it really
+ * seems independent of the color model. 50% red would be the same
+ * no mater how you represent it.
*/
-class Image_Color2 {
+class Image_Color2
+{
/**
* RGB value of the color. After it's assigned by the constructor it should
* never be null.
* @var array
*/
- protected $_rgb;
+ protected $rgb;
/**
* Color model used to read a non-RGB color. This is assigned by the
* constructor. If the source color is RGB no color model is needed so this
* will be null.
* @var Image_Color2_Model
*/
- protected $_model = null;
+ protected $model = null;
/**
* Construct a color from a string, array, or an instance of
@@ -119,12 +120,13 @@ class Image_Color2 {
* print $black->getHex(); \/\/ '#000000'
* </code>
*
- * @param array|string|Image_Color2_Model $src specifying a color.
+ * @param array|string|Image_Color2_Model $src specifying a color.
* Non-RGB arrays should include the type element to specify a
* color model. Strings will be interpreted as hex if they
* begin with a #, otherwise they'll be treated as named colors.
+ *
* @throws PEAR_Exception if the color cannot be loaded.
- * @uses _createModelReflectionMethod() If the color is non-RGB the
+ * @uses createModelReflectionMethod() If the color is non-RGB the
* function is used to construct an Image_Color2_Model for
* conversion.
*/
@@ -138,27 +140,27 @@ public function __construct($src)
if (!$type || $type == 'Rgb') {
$src['type'] = 'rgb';
- $this->_model = null;
- $this->_rgb = $src;
+ $this->model = null;
+ $this->rgb = $src;
} else {
- $method = self::_createModelReflectionMethod($type, 'fromArray');
- $this->_model = $method->invoke(null, $src);
+ $method = self::createModelReflectionMethod($type, 'fromArray');
+ $this->model = $method->invoke(null, $src);
}
} else if (is_string($src)) {
if ('#' == substr($src, 0, 1)) {
- $this->_model = Image_Color2_Model_Hex::fromString($src);
+ $this->model = Image_Color2_Model_Hex::fromString($src);
} else {
- $this->_model = Image_Color2_Model_Named::fromString($src);
+ $this->model = Image_Color2_Model_Named::fromString($src);
}
} else if ($src instanceof Image_Color2_Model) {
- $this->_model = $src;
+ $this->model = $src;
}
// at this point we either have a model, an rgb value, or a problem.
- if (!is_null($this->_model)) {
- $this->_rgb = $this->_model->getRgb();
+ if (!is_null($this->model)) {
+ $this->rgb = $this->model->getRgb();
}
- if (is_null($this->_rgb)) {
+ if (is_null($this->rgb)) {
throw new PEAR_Exception('Invalid color definition.');
}
}
@@ -166,21 +168,23 @@ public function __construct($src)
/**
* Return a ReflectionMethod of a Image_Color2_Model implementation found in
* the Image/Color2/Model directory.
- * @param string $type Name of a ColorModel implementation (i.e. for
- * Image_Color2_Model_Hsv this would be 'hsv').
- * @param string $methodName Name of a static factory method on the
+ *
+ * @param string $type Name of a ColorModel implementation (i.e. for
+ * Image_Color2_Model_Hsv this would be 'hsv').
+ * @param string $methodName Name of a static factory method on the
* ColorModel interface ('fromArray', 'fromString', or 'fromRgb').
+ *
* @return ReflectionMethod
* @throws PEAR_Exception if the class cannot be loaded, or it does not
* implement the Image_Color2_Model interface.
* @uses Image_Color2_Model As the interface for color conversion.
* @internal
*/
- protected static function _createModelReflectionMethod($type, $methodName)
+ protected static function createModelReflectionMethod($type, $methodName)
{
$type = ucfirst($type);
$classpath = 'Image/Color2/Model/' . $type . '.php';
- if (!include_once($classpath)) {
+ if (!include_once $classpath) {
throw new PEAR_Exception(
"File '{$classpath}' for $type was not found.");
}
@@ -206,9 +210,11 @@ protected static function _createModelReflectionMethod($type, $methodName)
* $color = Image_Color2::average($red, $blue);
* print $color->convertTo('named')->getString(); \/\/ 'purple'
* </code>
- * @param Image_Color2 $left
- * @param Image_Color2 $right
- * @return Image_Color2
+ *
+ * @param Image_Color2 $left Left color
+ * @param Image_Color2 $right Right color
+ *
+ * @return Image_Color2
*/
public static function average(Image_Color2 $left, Image_Color2 $right)
{
@@ -238,20 +244,21 @@ public static function average(Image_Color2 $left, Image_Color2 $right)
* $hsv = $blue->convertTo('hsv');
* print $hsv->getString(); \/\/ '240 100% 100%'
* </code>
-
- * @param string Name of a color model. If this variable is foo then a
- * class named Image_Color2_Model_Foo is required.
+ *
+ * @param string $type Name of a color model. If this variable is foo then a
+ * class named Image_Color2_Model_Foo is required.
+ *
* @return Image_Color2
* @throws PEAR_Exception if the desired color model cannot be found or it
* cannot convert the color.
- * @uses _createModelReflectionMethod() The function is used to
+ * @uses createModelReflectionMethod() The function is used to
* construct an Image_Color2_Model that is passed back to the
* constructor.
*/
public function convertTo($type)
{
- $method = self::_createModelReflectionMethod($type, 'fromRgb');
- $model = $method->invoke(null, $this->_rgb);
+ $method = self::createModelReflectionMethod($type, 'fromRgb');
+ $model = $method->invoke(null, $this->rgb);
if (is_null($model)) {
throw new PEAR_Exception(
"The '{$type}' color model couldn't convert the color.");
@@ -275,19 +282,21 @@ public function convertTo($type)
* print $color->getRgb(2); \/\/ 255
* print $color->getRgb('type'); \/\/ 'rgb'
* </code>
- * @param mixed $index An optional index value to select an element of
- * the array. A null value returns the entire array.
+ *
+ * @param mixed $index An optional index value to select an element of
+ * the array. A null value returns the entire array.
+ *
* @return mixed An array if no index parameter is provided. Otherwise,
* provided the index is valid, a member of the array.
- * @uses $_rgb Returns a copy of the array.
+ * @uses $rgb Returns a copy of the array.
*/
public function getRgb($index = null)
{
// return an element if requested
if (isset($index)) {
- return $this->_rgb[$index];
+ return $this->rgb[$index];
} else {
- return $this->_rgb;
+ return $this->rgb;
}
}
@@ -307,22 +316,23 @@ public function getRgb($index = null)
* print $color->getArray('type'); \/\/ 'rgb'
* </code>
*
- * @param mixed $index An optional index value to select an element of
- * the array. A null value returns the entire array.
+ * @param mixed $index An optional index value to select an element of
+ * the array. A null value returns the entire array.
+ *
* @return mixed An array if no index is provided. Otherwise, provided the
* index is valid, a member of the array.
- * @uses $_rgb If the color was specified as RGB.
- * @uses $_model If the color wasn't specified as RGB.
+ * @uses $rgb If the color was specified as RGB.
+ * @uses $model If the color wasn't specified as RGB.
* @uses Image_Color2_Model::getArray() For the color conversion if it
* wasn't originally RGB.
*/
public function getArray($index = null)
{
// get the array
- if (is_null($this->_model)) {
- $ret = $this->_rgb;
+ if (is_null($this->model)) {
+ $ret = $this->rgb;
} else {
- $ret = $this->_model->getArray();
+ $ret = $this->model->getArray();
}
// return an element if requested
@@ -353,7 +363,7 @@ public function getArray($index = null)
*/
public function getHex()
{
- return Image_Color2_Model_Hex::fromRgb($this->_rgb)->getString();
+ return Image_Color2_Model_Hex::fromRgb($this->rgb)->getString();
}
/**
@@ -379,10 +389,10 @@ public function getHex()
*/
public function getString()
{
- if (is_null($this->_model)) {
+ if (is_null($this->model)) {
return $this->getHex();
} else {
- return $this->_model->getString();
+ return $this->model->getString();
}
}
}
View
45 Image/Color2/Model.php
@@ -7,13 +7,13 @@
*
* PHP version 5
*
- * @category Image
- * @package Image_Color2
- * @author andrew morton <drewish@katherinehouse.com>
- * @copyright 2005
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
- * @version $Id$
- * @link http://pear.php.net/package/Image_Color2
+ * @category Image
+ * @package Image_Color2
+ * @author andrew morton <drewish@katherinehouse.com>
+ * @copyright 2005 Andrew Morton
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version SVN: $Id$
+ * @link http://pear.php.net/package/Image_Color2
*/
/**
@@ -26,13 +26,15 @@
* from RGB. This class should be imutable, meaning that once it's constructed
* the value is not changed.
*
- * @category Image
- * @package Image_Color2
- * @author andrew morton <drewish@katherinehouse.com>
- * @copyright 2005
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @category Image
+ * @package Image_Color2
+ * @author Andrew Morton <drewish@katherinehouse.com>
+ * @copyright 2005 Andrew Morton
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @link http://pear.php.net/package/Image_Color2
*/
-interface Image_Color2_Model {
+interface Image_Color2_Model
+{
/**
* Create an Image_Color2_Model from an RGB array.
*
@@ -45,9 +47,10 @@
* ignored as the alpha channel is a responsibility of the Image_Color2
* class.}}
*
- * @param array $rgb A PEAR style RGB array containing three integers
- * from 0 to 255 for the Red, Green, and Blue color components
- * followed by a 'type' => 'rgb' element.
+ * @param array $rgb A PEAR style RGB array containing three integers
+ * from 0 to 255 for the Red, Green, and Blue color components
+ * followed by a 'type' => 'rgb' element.
+ *
* @return Image_ColorModel
* @throws PEAR_Exception On an error an exception maybe thrown or null
* returned, it's up to the implementation.
@@ -73,9 +76,10 @@ static public function fromRgb($rgb);
* a percent sign (%) it will be divided by 100 and then treated as a
* zero to one floating point value.
*
- * @param array $array The values and order are specific to each color
- * model. There may be an optional type element at the end of the
- * array. i.e: array(0, 255, 0, 'type' => 'rgb')
+ * @param array $array The values and order are specific to each color
+ * model. There may be an optional type element at the end
+ * of the array. i.e: array(0, 255, 0, 'type' => 'rgb')
+ *
* @return Image_ColorModel
* @throws PEAR_Exception On an error an exception maybe thrown or null
* returned, it's up to the implementation.
@@ -116,7 +120,8 @@ static public function fromArray($array);
* HSL: '135, 100%, 40%' or '135 1.0 0.4'
* </pre>
*
- * @param string $str a string in a color model dependant format.
+ * @param string $str a string in a color model dependant format.
+ *
* @return Image_ColorModel
* @throws PEAR_Exception On an error an exception maybe thrown or null
* returned, it's up to the implementation.
Please sign in to comment.
Something went wrong with that request. Please try again.