private function canonizeClass($namespace, $class, $truncate)
    {
        $class = ltrim($class, '\\');
        $namespace = (string) $namespace;

        $namespace = $namespace === '' ? '' : trim($namespace, '\\') . '\\';

        if (strncmp($class, $namespace, strlen($namespace)) !== 0) {
            return false;
        }

        return $truncate ? substr($class, strlen($namespace)) : $class;
    }