protected function checkType($expectedType, $value, $nullAllowed = false)
    {
        $invalidType = null;
        $valueType = gettype($value);
        $nullAllowed = (boolean) $nullAllowed;

        if ($valueType === 'object') {
            if (!is_a($value, $expectedType)) {
                $invalidType = get_class($value);
            }
        } elseif ($expectedType !== $valueType) {
            $invalidType = $valueType;
        }

        if ($invalidType !== null && ($nullAllowed === false || ($nullAllowed === true && $value !== null))) {
            throw new CmisInvalidArgumentException(
                sprintf(
                    'Argument of type "%s" given but argument of type "%s" was expected.',
                    $invalidType,
                    $expectedType
                ),
                1413440336
            );
        }

        return true;
    }