]> git.andy128k.dev Git - missing-tools.git/commitdiff
type hints and style fixes
authorAndrey Kutejko <andy128k@gmail.com>
Sat, 5 Nov 2016 14:33:30 +0000 (15:33 +0100)
committerAndrey Kutejko <andy128k@gmail.com>
Sat, 5 Nov 2016 14:33:30 +0000 (15:33 +0100)
src/array.php
src/cli.php
src/container.php
src/dateformat.php
src/htmlbuilder.php
src/mixins.php
src/shell.php

index 39e03e3a001db7fcdd728e02e38f138c70ab83de..7978a3e08b9547df08fd3c4d093d4ec895dc900f 100644 (file)
@@ -4,7 +4,13 @@ namespace PFF;
 
 final class Arr
 {
-    public static function get($array, $key, $default=null)
+    /**
+     * @param array $array
+     * @param string|integer $key
+     * @param mixed $default
+     * @return mixed
+     */
+    public static function get(array $array, $key, $default=null)
     {
         if (array_key_exists($key, $array))
             return $array[$key];
@@ -12,21 +18,37 @@ final class Arr
             return $default;
     }
 
-    public static function ensureKeyExists(&$array, $key, $default=null)
+    /**
+     * @param array $array
+     * @param string|integer $key
+     * @param mixed $default
+     */
+    public static function ensureKeyExists(array &$array, $key, $default=null)
     {
         if (!array_key_exists($key, $array))
-            return $array[$key] = $default;
+            $array[$key] = $default;
     }
 
-    public static function pushToKey(&$array, $key, $value)
+    /**
+     * @param array $array
+     * @param string|integer $key
+     * @param mixed $value
+     */
+    public static function pushToKey(array &$array, $key, $value)
     {
         if (array_key_exists($key, $array))
-            return $array[$key][] = $value;
+            $array[$key][] = $value;
         else
-            return $array[$key] = array($value);
+            $array[$key] = array($value);
     }
 
-    public static function pop(&$array, $key, $default=null)
+    /**
+     * @param array $array
+     * @param string|integer $key
+     * @param mixed $default
+     * @return mixed
+     */
+    public static function pop(array &$array, $key, $default=null)
     {
         if (array_key_exists($key, $array)) {
             $value = $array[$key];
@@ -37,7 +59,11 @@ final class Arr
         }
     }
 
-    public static function flatten($array)
+    /**
+     * @param array $array
+     * @return array
+     */
+    public static function flatten(array $array)
     {
         $result = array();
         array_walk_recursive($array, function ($value) use (&$result) {
@@ -46,7 +72,12 @@ final class Arr
         return $result;
     }
 
-    public static function pluck($array, $key)
+    /**
+     * @param array $array
+     * @param string|integer $key
+     * @return array
+     */
+    public static function pluck(array $array, $key)
     {
         $result = array();
         foreach ($array as $item)
@@ -54,4 +85,3 @@ final class Arr
         return $result;
     }
 }
-
index 33d87e51bad563383c36c502c9d780724d094169..05ec6f57f6fc68a2af6ae8212e9ce3f401ae6ad3 100644 (file)
@@ -11,7 +11,7 @@ abstract class CLI
             return $argv;
         if (@is_array($_SERVER['argv']))
             return $_SERVER['argv'];
-        throw new Exception("Could not read command arguments (register_argc_argv=Off?)");
+        throw new \Exception("Could not read command arguments (register_argc_argv=Off?)");
     }
 
     protected abstract function commands();
@@ -86,4 +86,3 @@ abstract class CLI
         }
     }
 }
-
index b786268d02947b07454f534ec8d0106afeadaa6b..9f1543b3a195db1a9cd157853b468bc1bc77e804 100644 (file)
@@ -37,13 +37,13 @@ class Container
         switch ($name) {
         case 'set':
             $this->values[$args[0]] = array('value', $args[1]);
-            break;
+            return $this;
         case 'setFunction':
             $this->values[$args[0]] = array('function', $args[1]);
-            break;
+            return $this;
         case 'setFactory':
             $this->values[$args[0]] = array('factory', $args[1]);
-            break;
+            return $this;
         default:
             return $this->getWithArgs($name, $args);
         }
@@ -63,4 +63,3 @@ class Container
         return call_user_func_array(array(self::getInstance(), $name), $args);
     }
 }
-
index 8bb76a2dd86d3e8f6ac7d7234c00334e73d3aeac..7a96a56304a5ac0faf8110db3f5d8cf130bee93b 100644 (file)
@@ -170,7 +170,7 @@ final class DateFormat
                 $result .= ' '.$controls[6];
                 break;
             default:
-                throw new Exception('Bad time format');
+                throw new \Exception('Bad time format');
         }
         return $result;
     }
index 32385d0492a492e9626ab51b0e6b71b78d5f7be2..9e0a9ed44581daed875ec227b166235cda4066ad 100644 (file)
@@ -4,6 +4,10 @@ namespace PFF\HtmlBuilder;
 
 class Text
 {
+    /**
+     * @param string $text
+     * @return string
+     */
     public static function escape($text)
     {
         return htmlspecialchars($text, ENT_COMPAT, 'UTF-8');
@@ -14,6 +18,11 @@ class Tag
 {
     private $name, $selfClose, $attributes, $inner=array();
 
+    /**
+     * @param string $name
+     * @param array $attributes
+     * @param mixed|null $inner
+     */
     public function __construct($name, $attributes=array(), $inner=null)
     {
         $this->name = $name;
@@ -26,6 +35,9 @@ class Tag
             $this->append($item);
     }
 
+    /**
+     * @return Tag
+     */
     public static function create(/*name[, attributes, [... inner]]*/)
     {
         $args = func_get_args();
@@ -34,25 +46,43 @@ class Tag
         return new Tag($name, $attributes, $args);
     }
 
-    public static function __callStatic($method, $args)
+    /**
+     * @param string $name
+     * @param array $args
+     * @return Tag
+     */
+    public static function __callStatic($name, $args)
     {
         $attributes = array_shift($args);
-        return new Tag($method, $attributes, $args);
+        return new Tag($name, $attributes, $args);
     }
 
+    /**
+     * @param string $name
+     * @param string $value
+     * @return Tag
+     */
     public function attr($name, $value)
     {
         $this->attributes[$name] = $value;
         return $this;
     }
 
+    /**
+     * @param string $name
+     * @return Tag
+     */
     public function unsetAttr($name)
     {
         unset($this->attributes[$name]);
         return $this;
     }
 
-    public function attrs($attributes)
+    /**
+     * @param array $attributes dictionary
+     * @return Tag
+     */
+    public function attrs(array $attributes)
     {
         foreach ($attributes as $k => $v) {
             if ($k == 'class') {
@@ -74,7 +104,11 @@ class Tag
             $classes = explode(' ', $classes);
         return $classes;
     }
-    
+
+    /**
+     * @param string $class
+     * @return Tag
+     */
     public function addClass($class)
     {
         $classes = $this->getListAttribute('class');
@@ -84,6 +118,10 @@ class Tag
         return $this;
     }
 
+    /**
+     * @param string $class
+     * @return Tag
+     */
     public function removeClass($class)
     {
         $classes = $this->getListAttribute('class');
@@ -94,6 +132,12 @@ class Tag
         return $this;
     }
 
+    /**
+     * @param string $name
+     * @param mixed $value
+     * @param boolean $condition
+     * @return Tag
+     */
     public function toggleAttr($name, $value, $condition)
     {
         return $condition
@@ -101,6 +145,11 @@ class Tag
             : $this->unsetAttr($name);
     }
 
+    /**
+     * @param string $class
+     * @param boolean $condition
+     * @return Tag
+     */
     public function toggleClass($class, $condition)
     {
         return $condition
@@ -108,6 +157,10 @@ class Tag
             : $this->removeClass($class);
     }
 
+    /**
+     * @param mixed $item
+     * @return Tag
+     */
     public function append($item)
     {
         if (is_array($item)) {
@@ -121,6 +174,10 @@ class Tag
         return $this;
     }
 
+    /**
+     * @param string $raw
+     * @return Tag
+     */
     public function raw($raw)
     {
         if (is_array($raw)) {
@@ -131,6 +188,9 @@ class Tag
         return $this;
     }
 
+    /**
+     * @return string
+     */
     public function html()
     {
         $s = '<'.$this->name;
@@ -150,9 +210,11 @@ class Tag
         return $s;
     }
 
+    /**
+     * @return string
+     */
     public function __toString()
     {
         return $this->html();
     }
 }
-
index b0b8f03bd3a3d603baf6a906a53b995e376bcde2..3026b13601ecb3edf2b131de65de370372e527b8 100644 (file)
@@ -10,7 +10,7 @@ class Mixins
     {
         foreach ($mixins as $class) {
             if (!class_exists($class))
-                throw new Exception('Tried to inherit non-existant class \''.$class.'\'.');
+                throw new \Exception('Tried to inherit non-existant class \''.$class.'\'.');
 
             $mixin = new $class($object);
             $methods = get_class_methods($mixin);
@@ -27,7 +27,7 @@ class Mixins
     {
         $m = strtolower($method);
         if (!isset($this->methods[$m]))
-            throw new Exception('Call to undefined method ' . get_class($this) . "::$method()");
+            throw new \Exception('Call to undefined method ' . get_class($this) . "::$method()");
 
         $this->current_call_method = $method;
         $this->current_call_mixins = $this->methods[$m];
@@ -40,11 +40,11 @@ class Mixins
     public function call_next_method()
     {
         if ($this->current_call_mixins === null)
-            throw new Exception('call_next_method is invoked outside of mixin method.');
+            throw new \Exception('call_next_method is invoked outside of mixin method.');
 
         $mixin = array_pop($this->current_call_mixins);
         if ($mixin === null)
-            throw new Exception('No next method for ' . get_class($this) . "::$method()");
+            throw new \Exception('No next method for ' . get_class($this) . "::$method()");
 
         return call_user_func_array(array($mixin, $this->current_call_method), func_get_args());
     }
index 03e8468766ec4d0ededf5366bc6c0460d6a0171f..6aa5f0dd6665d20c415bc97cb2b26bca5b7f018a 100644 (file)
@@ -6,10 +6,10 @@ class Shell
 {
     public static function call()
     {
-        return self::callv(func_get_args());
+        self::callv(func_get_args());
     }
 
-    public static function callv($command)
+    public static function callv(array $command)
     {
         $str = '';
         foreach ($command as $part) {
@@ -24,4 +24,3 @@ class Shell
         proc_close($process);
     }
 }
-