{"action":"created","issue":{"url":"https://api.github.com/repos/box/spout/issues/362","repository_url":"https://api.github.com/repos/box/spout","labels_url":"https://api.github.com/repos/box/spout/issues/362/labels{/name}","comments_url":"https://api.github.com/repos/box/spout/issues/362/comments","events_url":"https://api.github.com/repos/box/spout/issues/362/events","html_url":"https://github.com/box/spout/issues/362","id":191889456,"number":362,"title":"Change request to make InvalidSheetNameException more descriptive","user":{"login":"cmanley","id":591285,"avatar_url":"https://avatars.githubusercontent.com/u/591285?v=3","gravatar_id":"","url":"https://api.github.com/users/cmanley","html_url":"https://github.com/cmanley","followers_url":"https://api.github.com/users/cmanley/followers","following_url":"https://api.github.com/users/cmanley/following{/other_user}","gists_url":"https://api.github.com/users/cmanley/gists{/gist_id}","starred_url":"https://api.github.com/users/cmanley/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cmanley/subscriptions","organizations_url":"https://api.github.com/users/cmanley/orgs","repos_url":"https://api.github.com/users/cmanley/repos","events_url":"https://api.github.com/users/cmanley/events{/privacy}","received_events_url":"https://api.github.com/users/cmanley/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2016-11-27T22:15:08Z","updated_at":"2016-11-28T23:50:09Z","closed_at":null,"body":"**Box\\Spout\\Writer\\Common\\Sheet.php**\r\n\r\n**Background:**\r\nI was setting sheet names to year month periods such as 201611 (an int) and getting InvalidSheetNameException exceptions. I traced it down to being the !== operator in doesContainInvalidCharacters() which may be something for a different issue report.\r\n\r\n**Change request:**\r\nI could create a fork and a pull request, but this is fairly short...\r\n\r\nReplace first 2 lines of setName() with:\r\n```php\r\nif (!$this->isNameValid($name, $error_reason)) {\r\n            $errorMessage = \"The sheet's name is invalid ($error_reason). It did not meet at least one of these requirements:\\n\";\r\n```\r\nNote the $error_reason which receives the reason and prevents unnecessary hair pulling.\r\n\r\nReplace isNameValid() with:\r\n```php\r\n    /**\r\n     * Returns whether the given sheet's name is valid.\r\n     * @see Sheet::setName for validity rules.\r\n     *\r\n     * @param string $name\r\n     * @param string &$error_reason optional, receives reason on error.\r\n     * @return bool TRUE if the name is valid, FALSE otherwise.\r\n     */\r\n    protected function isNameValid($name, &$error_reason = null)\r\n    {\r\n        if (!(is_string($name) || is_int($name))) {\r\n        \t$error_reason = 'not a string or int';\r\n            return false;\r\n        }\r\n        $nameLength = $this->stringHelper->getStringLength($name);\r\n        if (!$nameLength) {\r\n        \t$error_reason = 'zero length';\r\n        \treturn false;\r\n        }\r\n        if ($nameLength > self::MAX_LENGTH_SHEET_NAME) {\r\n        \t$error_reason = \"length $nameLength is too long\";\r\n        \treturn false;\r\n        }\r\n        if ($this->doesContainInvalidCharacters($name)) {\r\n        \t$error_reason = 'contains invalid characters';\r\n        \treturn false;\r\n        }\r\n        if (!$this->isNameUnique($name)) {\r\n        \t$error_reason = 'not unique';\r\n        \treturn false;\r\n        }\r\n        if ($this->doesStartOrEndWithSingleQuote($name)) {\r\n        \t$error_reason = 'starts or ends with single quote';\r\n        \treturn false;\r\n        }\r\n        return true;\r\n    }\r\n```\r\n"},"comment":{"url":"https://api.github.com/repos/box/spout/issues/comments/263432493","html_url":"https://github.com/box/spout/issues/362#issuecomment-263432493","issue_url":"https://api.github.com/repos/box/spout/issues/362","id":263432493,"user":{"login":"adrilo","id":7086917,"avatar_url":"https://avatars.githubusercontent.com/u/7086917?v=3","gravatar_id":"","url":"https://api.github.com/users/adrilo","html_url":"https://github.com/adrilo","followers_url":"https://api.github.com/users/adrilo/followers","following_url":"https://api.github.com/users/adrilo/following{/other_user}","gists_url":"https://api.github.com/users/adrilo/gists{/gist_id}","starred_url":"https://api.github.com/users/adrilo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/adrilo/subscriptions","organizations_url":"https://api.github.com/users/adrilo/orgs","repos_url":"https://api.github.com/users/adrilo/repos","events_url":"https://api.github.com/users/adrilo/events{/privacy}","received_events_url":"https://api.github.com/users/adrilo/received_events","type":"User","site_admin":false},"created_at":"2016-11-28T23:50:09Z","updated_at":"2016-11-28T23:50:09Z","body":"Oh ok, then that makes sense. I won't keep the `is_int()` check. The API defines that the value needs to be a string, so it's the developer's responsibility to cast the passed in value to string if it's not already a string."}}
{"actor":{"display_login":"adrilo"}}