Code Duplication    Length = 40-43 lines in 2 locations

src/Hydra/ApiDocumentationBuilder.php 1 location

@@ 358-397 (lines=40) @@
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 'string';
372
373
            case Type::BUILTIN_TYPE_INT:
374
                return 'integer';
375
376
            case Type::BUILTIN_TYPE_FLOAT:
377
                return 'number';
378
379
            case Type::BUILTIN_TYPE_BOOL:
380
                return 'boolean';
381
382
            case Type::BUILTIN_TYPE_OBJECT:
383
                $className = $type->getClassName();
384
385
                if ($className) {
386
                    if (is_subclass_of($className, \DateTimeInterface::class)) {
387
                        return 'string';
388
                    }
389
390
                    $className = $type->getClassName();
391
                    if ($this->resourceClassResolver->isResourceClass($className)) {
392
                        return ['$ref' => sprintf('#/definitions/%s', $this->resourceMetadataFactory->create($className)->getShortName())];
393
                    }
394
                }
395
           break;
396
        }
397
    }
398
399
    /**
400
     * Builds the JSON-LD context for the API documentation.

src/Swagger/ApiDocumentationBuilder.php 1 location

@@ 249-291 (lines=43) @@
246
     *
247
     * @return string|null
248
     */
249
    private function getRange(PropertyMetadata $propertyMetadata)
250
    {
251
        $type = $propertyMetadata->getType();
252
        if (!$type) {
253
            return;
254
        }
255
256
        if ($type->isCollection() && $collectionType = $type->getCollectionValueType()) {
257
            $type = $collectionType;
258
        }
259
260
        switch ($type->getBuiltinType()) {
261
            case Type::BUILTIN_TYPE_STRING:
262
                return 'string';
263
264
            case Type::BUILTIN_TYPE_INT:
265
                return 'integer';
266
267
            case Type::BUILTIN_TYPE_FLOAT:
268
                return 'number';
269
270
            case Type::BUILTIN_TYPE_BOOL:
271
                return 'boolean';
272
273
            case Type::BUILTIN_TYPE_OBJECT:
274
                $className = $type->getClassName();
275
276
                if ($className) {
277
                    if (is_subclass_of($className, \DateTimeInterface::class)) {
278
                        return 'string';
279
                    }
280
281
                    $className = $type->getClassName();
282
                    if ($this->resourceClassResolver->isResourceClass($className)) {
283
                        return ['$ref' => sprintf('#/definitions/%s', $this->resourceMetadataFactory->create($className)->getShortName())];
284
                    }
285
                }
286
            break;
287
            default:
288
                return 'null';
289
            break;
290
        }
291
    }
292
}
293