Box\Spout\Writer\Common\Sheet::throwIfNameIsInvalid PHP Method

throwIfNameIsInvalid() protected method

Throws an exception if the given sheet's name is not valid.
See also: Sheet::setName for validity rules.
protected throwIfNameIsInvalid ( string $name ) : void
$name string
return void
    protected function throwIfNameIsInvalid($name)
    {
        if (!is_string($name)) {
            $actualType = gettype($name);
            $errorMessage = "The sheet's name is invalid. It must be a string ({$actualType} given).";
            throw new InvalidSheetNameException($errorMessage);
        }
        $failedRequirements = [];
        $nameLength = $this->stringHelper->getStringLength($name);
        if (!$this->isNameUnique($name)) {
            $failedRequirements[] = 'It should be unique';
        } else {
            if ($nameLength === 0) {
                $failedRequirements[] = 'It should not be blank';
            } else {
                if ($nameLength > self::MAX_LENGTH_SHEET_NAME) {
                    $failedRequirements[] = 'It should not exceed 31 characters';
                }
                if ($this->doesContainInvalidCharacters($name)) {
                    $failedRequirements[] = 'It should not contain these characters: \\ / ? * : [ or ]';
                }
                if ($this->doesStartOrEndWithSingleQuote($name)) {
                    $failedRequirements[] = 'It should not start or end with a single quote';
                }
            }
        }
        if (count($failedRequirements) !== 0) {
            $errorMessage = "The sheet's name (\"{$name}\") is invalid. It did not respect these rules:\n - ";
            $errorMessage .= implode("\n - ", $failedRequirements);
            throw new InvalidSheetNameException($errorMessage);
        }
    }