Code Duplication    Length = 20-22 lines in 2 locations

services/NorthWind/NorthWindQueryProvider.php 2 locations

@@ 366-385 (lines=20) @@
363
        $srcClass = get_class($sourceEntityInstance);
364
        $navigationPropName = $targetProperty->getName();
365
        if ($srcClass === 'Order') {
366
            if ($navigationPropName === 'Customer') {
367
                if (empty($sourceEntityInstance->CustomerID)) {
368
                    $result = null;
369
                } else {
370
                    $query = "SELECT * FROM Customers WHERE CustomerID = '$sourceEntityInstance->CustomerID'";
371
                    $stmt = sqlsrv_query($this->_connectionHandle, $query);
372
                    if ($stmt === false) {
373
                        $errorAsString = self::_getSQLSRVError();
374
                        throw ODataException::createInternalServerError($errorAsString);
375
                    }
376
377
                    if (!sqlsrv_has_rows($stmt)) {
378
                        $result = null;
379
                    }
380
381
                    $result = $this->_serializeCustomer(sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC));
382
                }
383
            } else {
384
                die('Customer does not have navigation porperty with name: ' . $navigationPropName);
385
            }
386
        } elseif ($srcClass === 'Order_Details') {
387
            if ($navigationPropName === 'Order') {
388
                if (empty($sourceEntityInstance->OrderID)) {
@@ 386-407 (lines=22) @@
383
            } else {
384
                die('Customer does not have navigation porperty with name: ' . $navigationPropName);
385
            }
386
        } elseif ($srcClass === 'Order_Details') {
387
            if ($navigationPropName === 'Order') {
388
                if (empty($sourceEntityInstance->OrderID)) {
389
                    $result = null;
390
                } else {
391
                    $query = "SELECT * FROM Orders WHERE OrderID = $sourceEntityInstance->OrderID";
392
                    $stmt = sqlsrv_query($this->_connectionHandle, $query);
393
                    if ($stmt === false) {
394
                        $errorAsString = self::_getSQLSRVError();
395
                        throw ODataException::createInternalServerError($errorAsString);
396
                    }
397
398
                    if (!sqlsrv_has_rows($stmt)) {
399
                        $result = null;
400
                    }
401
402
                    $result = $this->_serializeOrder(sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC));
403
                }
404
            } else {
405
                die('Order_Details does not have navigation porperty with name: ' . $navigationPropName);
406
            }
407
        }
408
409
        return $result;
410
    }