Fix class name.
authorJan Schneider <jan@horde.org>
Fri, 15 Jan 2010 23:32:56 +0000 (00:32 +0100)
committerJan Schneider <jan@horde.org>
Fri, 15 Jan 2010 23:32:56 +0000 (00:32 +0100)
Use typehints.
Don't hardcode string length.

framework/Perms/lib/Horde/Perms/Datatree.php
framework/Perms/lib/Horde/Perms/Sql.php

index 51cce6a..397cd0d 100644 (file)
@@ -146,12 +146,8 @@ class Horde_Perms_Datatree extends Horde_Perms
      *                                                     object.
      * @throws Horde_Perms_Exception
      */
-    public function addPermission($perm)
+    public function addPermission(Horde_Perms_Permission_DataTreeObject $perm)
     {
-        if (!($perm instanceof Horde_Perms_Permission_DataTreeObject)) {
-            throw Horde_Perms_Exception('Permissions must be Horde_Perms_Permission_DataTreeObject objects.');
-        }
-
         $name = $perm->getName();
         if (empty($name)) {
             throw Horde_Perms_Exception('Permission names must be non-empty.');
@@ -170,12 +166,8 @@ class Horde_Perms_Datatree extends Horde_Perms
      * @param boolean $force                               Force to remove
      *                                                     every child.
      */
-    public function removePermission($perm, $force = false)
+    public function removePermission(Horde_Perms_Permission_DataTreeObject $perm, $force = false)
     {
-        if (!($perm instanceof Horde_Perms_Permission_DataTreeObject)) {
-            throw Horde_Perms_Exception('Permissions must be Horde_Perms_Permission_DataTreeObject objects.');
-        }
-
         $keys = $this->_datatree->get(DATATREE_FORMAT_FLAT, $perm->name, true);
         foreach ($keys as $key) {
             $this->_cache->expire('perm_' . $this->_cacheVersion . $key);
index 24f770e..4b96887 100644 (file)
@@ -181,12 +181,8 @@ class Horde_Perms_Sql extends Horde_Perms
      * @return TODO
      * @throws Horde_Perms_Exception
      */
-    public function addPermission($perm)
+    public function addPermission(Horde_Perms_Permission_SqlObject $perm)
     {
-        if (!($perm instanceof Horde_Perms_Permission_SqlObject)) {
-            throw new Horde_Perms_Exception('Permissions must be a Horde_Perms_Permission_SqlObject object.');
-        }
-
         $name = $perm->getName();
         if (empty($name)) {
             throw new Horde_Perms_Exception('Permission name must be non-empty.');
@@ -199,8 +195,9 @@ class Horde_Perms_Sql extends Horde_Perms
         $id = $this->_write_db->nextId('horde_perms');
 
         // remove root from the name
-        if (substr($name, 0, 3) == (Horde_Perms::ROOT . ':')) {
-            $name = substr($name, 3);
+        $root = Horde_Perms::ROOT . ':';
+        if (substr($name, 0, strlen($root)) == ($root)) {
+            $name = substr($name, strlen($root));
         }
 
         // build parents
@@ -239,12 +236,8 @@ class Horde_Perms_Sql extends Horde_Perms
      * @return TODO
      * @throws Horde_Perms_Exception
      */
-    public function removePermission($perm, $force = false)
+    public function removePermission(Horde_Perms_Permission_SqlObject $perm, $force = false)
     {
-        if (!($perm instanceof Horde_Perms_Permissions_SqlObject)) {
-            throw new Horde_Perms_Exception('Permissions must be Horde_Perms_Permission_SqlObject objects.');
-        }
-
         $name = $perm->getName();
         $this->_cache->expire('perm_sql' . $this->_cacheVersion . $name);
         $this->_cache->expire('perm_sql_exists_' . $this->_cacheVersion . $name);