Code Duplication    Length = 41-44 lines in 2 locations

src/Hydra/ApiDocumentationBuilder.php 1 location

@@ 358-398 (lines=41) @@
355
     *
356
     * @return string|null
357
     */
358
    private function getRange(PropertyMetadata $propertyMetadata)
359
    {
360
        $type = $propertyMetadata->getType();
361
        if (!$type) {
362
            return;
363
        }
364
365
        if ($type->isCollection() && $collectionType = $type->getCollectionValueType()) {
366
            $type = $collectionType;
367
        }
368
369
        switch ($type->getBuiltinType()) {
370
            case Type::BUILTIN_TYPE_STRING:
371
                return 'xmls:string';
372
373
            case Type::BUILTIN_TYPE_INT:
374
                return 'xmls:integer';
375
376
            case Type::BUILTIN_TYPE_FLOAT:
377
                return 'xmls:number';
378
379
            case Type::BUILTIN_TYPE_BOOL:
380
                return 'xmls:boolean';
381
382
            case Type::BUILTIN_TYPE_OBJECT:
383
                $className = $type->getClassName();
384
385
                if (null !== $className) {
386
                    $reflection = new \ReflectionClass($className);
387
                    if ($reflection->implementsInterface(\DateTimeInterface::class)) {
388
                        return 'xmls:dateTime';
389
                    }
390
391
                    $className = $type->getClassName();
392
                    if ($this->resourceClassResolver->isResourceClass($className)) {
393
                        return sprintf('#%s', $this->resourceMetadataFactory->create($className)->getShortName());
394
                    }
395
                }
396
           break;
397
        }
398
    }
399
400
    /**
401
     * Builds the JSON-LD context for the API documentation.

src/Swagger/ApiDocumentationBuilder.php 1 location

@@ 301-344 (lines=44) @@
298
     *
299
     * @return string|null
300
     */
301
    private function getRange(PropertyMetadata $propertyMetadata)
302
    {
303
        $type = $propertyMetadata->getType();
304
        if (!$type) {
305
            return;
306
        }
307
308
        if ($type->isCollection() && $collectionType = $type->getCollectionValueType()) {
309
            $type = $collectionType;
310
        }
311
312
        switch ($type->getBuiltinType()) {
313
            case Type::BUILTIN_TYPE_STRING:
314
                return 'string';
315
316
            case Type::BUILTIN_TYPE_INT:
317
                return 'integer';
318
319
            case Type::BUILTIN_TYPE_FLOAT:
320
                return 'number';
321
322
            case Type::BUILTIN_TYPE_BOOL:
323
                return 'boolean';
324
325
            case Type::BUILTIN_TYPE_OBJECT:
326
                $className = $type->getClassName();
327
328
                if (null !== $className) {
329
                    $reflection = new \ReflectionClass($className);
330
                    if ($reflection->implementsInterface(\DateTimeInterface::class)) {
331
                        return 'string';
332
                    }
333
334
                    $className = $type->getClassName();
335
                    if ($this->resourceClassResolver->isResourceClass($className)) {
336
                        return ['$ref' => sprintf('#/definitions/%s', $this->resourceMetadataFactory->create($className)->getShortName())];
337
                    }
338
                }
339
            break;
340
            default:
341
                return 'null';
342
            break;
343
        }
344
    }
345
}
346