{"action":"closed","issue":{"url":"https://api.github.com/repos/andela-kerinoso/potato-orm/issues/3","labels_url":"https://api.github.com/repos/andela-kerinoso/potato-orm/issues/3/labels{/name}","comments_url":"https://api.github.com/repos/andela-kerinoso/potato-orm/issues/3/comments","events_url":"https://api.github.com/repos/andela-kerinoso/potato-orm/issues/3/events","html_url":"https://github.com/andela-kerinoso/potato-orm/issues/3","id":111326422,"number":3,"title":"BackBone.php - Methods should be as atomic as possible, not looking like hell","user":{"login":"unicodeveloper","id":2946769,"avatar_url":"https://avatars.githubusercontent.com/u/2946769?v=3","gravatar_id":"","url":"https://api.github.com/users/unicodeveloper","html_url":"https://github.com/unicodeveloper","followers_url":"https://api.github.com/users/unicodeveloper/followers","following_url":"https://api.github.com/users/unicodeveloper/following{/other_user}","gists_url":"https://api.github.com/users/unicodeveloper/gists{/gist_id}","starred_url":"https://api.github.com/users/unicodeveloper/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/unicodeveloper/subscriptions","organizations_url":"https://api.github.com/users/unicodeveloper/orgs","repos_url":"https://api.github.com/users/unicodeveloper/repos","events_url":"https://api.github.com/users/unicodeveloper/events{/privacy}","received_events_url":"https://api.github.com/users/unicodeveloper/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-10-14T05:30:08Z","updated_at":"2015-10-30T09:58:06Z","closed_at":"2015-10-30T09:58:06Z","body":"```php\r\npublic static function mapClassToTable($className)\r\n    {\r\n        $demarcation = strrpos($className, '\\\\', -1);\r\n        if ($demarcation !== false) {\r\n            $table = strtolower(substr($className, $demarcation + 1));\r\n        } else {\r\n            $table = strtolower($className);\r\n        }\r\n        if (! self::checkForTable($table)) {\r\n            $temp = ucfirst($table);\r\n            if (self::checkForTable($temp)) {\r\n                return $temp;\r\n            } else {\r\n                $arrayOfCharInTable = str_split($table);\r\n                if ($arrayOfCharInTable[count($arrayOfCharInTable) - 1] === 's') {\r\n                    array_pop($arrayOfCharInTable);\r\n                    $table = implode($arrayOfCharInTable);\r\n                } else {\r\n                    $table .= 's';\r\n                }\r\n                if (! self::checkForTable($table)) {\r\n                    $temp = ucfirst($table);\r\n                    if (self::checkForTable($temp)) {\r\n                        return $temp;\r\n                    } else {\r\n                        throw new TableDoesNotExistException;\r\n                    }\r\n                }\r\n            }\r\n        }\r\n        return $table;\r\n    }\r\n```\r\n\r\nThis function is doing too much.\r\n\r\n```php\r\n$arrayOfCharInTable = str_split($table);\r\n                if ($arrayOfCharInTable[count($arrayOfCharInTable) - 1] === 's') {\r\n                    array_pop($arrayOfCharInTable);\r\n                    $table = implode($arrayOfCharInTable);\r\n                } else {\r\n                    $table .= 's';\r\n                }\r\n```\r\n\r\ncan be abstracted into another method and just called  with the necessary arguments.\r\n\r\n```php\r\nif (! self::checkForTable($table)) {\r\n                    $temp = ucfirst($table);\r\n                    if (self::checkForTable($temp)) {\r\n                        return $temp;\r\n                    } else {\r\n                        throw new TableDoesNotExistException;\r\n                    }\r\n                }\r\n```\r\n\r\nThis is repeated, so you can have a method to accomodate it, then logically include it in the `mapClassToTable()` methods."}}