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 '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 ($className) {
386
                    if (is_subclass_of($className, \DateTimeInterface::class)) {
387
                        return 'xmls:dateTime';
388
                    }
389
390
                    $className = $type->getClassName();
391
                    if ($this->resourceClassResolver->isResourceClass($className)) {
392
                        return sprintf('#%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

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