Skip to content

Commit dad1fb4

Browse files
author
Oleksii Korshenko
committed
MAGETWO-65199: [GitHub][PR] [PSR-2 Compliance] Fix #8612: Hundreds of PHPCS-based static tests violations in mainline #8685
2 parents d8d3d45 + 378ac7a commit dad1fb4

File tree

29 files changed

+573
-60
lines changed

29 files changed

+573
-60
lines changed

app/code/Magento/CacheInvalidate/Model/PurgeCache.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ public function sendPurgeRequest($tagsPattern)
6767
'1.1',
6868
$headers
6969
);
70+
$socketAdapter->read();
7071
$socketAdapter->close();
7172
} catch (\Exception $e) {
7273
$this->logger->critical($e->getMessage(), compact('server', 'tagsPattern'));

app/code/Magento/CacheInvalidate/Test/Unit/Model/PurgeCacheTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ public function testSendPurgeRequest($hosts)
7171
$this->socketAdapterMock->expects($this->at($i++))
7272
->method('write')
7373
->with('PURGE', $uri, '1.1', ['X-Magento-Tags-Pattern' => 'tags', 'Host' => $uri->getHost()]);
74+
$this->socketAdapterMock->expects($this->at($i++))
75+
->method('read');
7476
$i++;
7577
}
7678
$this->socketAdapterMock->expects($this->exactly(count($uris)))

app/code/Magento/Catalog/view/frontend/layout/catalog_product_view.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@
9494
<argument name="at_call" xsi:type="string">getShortDescription</argument>
9595
<argument name="at_code" xsi:type="string">short_description</argument>
9696
<argument name="css_class" xsi:type="string">overview</argument>
97-
<argument name="at_label" translate="true" xsi:type="string">none</argument>
97+
<argument name="at_label" xsi:type="string">none</argument>
9898
<argument name="title" translate="true" xsi:type="string">Overview</argument>
9999
<argument name="add_attribute" xsi:type="string">itemprop="description"</argument>
100100
</arguments>

app/code/Magento/ConfigurableProduct/Model/Product/Type/Configurable/Price.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,15 @@ public function getFinalPrice($qty, $product)
3939
*/
4040
public function getPrice($product)
4141
{
42-
if ($product->getCustomOption('simple_product')) {
43-
return $product->getCustomOption('simple_product')->getProduct()->getPrice();
44-
} else {
45-
return 0;
42+
if (!empty($product)) {
43+
$simpleProductOption = $product->getCustomOption('simple_product');
44+
if (!empty($simpleProductOption)) {
45+
$simpleProduct = $simpleProductOption->getProduct();
46+
if (!empty($simpleProduct)) {
47+
return $simpleProduct->getPrice();
48+
}
49+
}
4650
}
51+
return 0;
4752
}
4853
}

app/code/Magento/Fedex/Model/Carrier.php

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1570,9 +1570,9 @@ private function processTrackingDetails(\stdClass $trackInfo)
15701570
'progressdetail' => [],
15711571
];
15721572

1573-
if (!empty($trackInfo->ShipTimestamp)) {
1574-
$datetime = \DateTime::createFromFormat(\DateTime::ISO8601, $trackInfo->ShipTimestamp);
1575-
$result['shippeddate'] = $datetime->format('Y-m-d');
1573+
$datetime = $this->parseDate(!empty($trackInfo->ShipTimestamp) ? $trackInfo->ShipTimestamp : null);
1574+
if ($datetime) {
1575+
$result['shippeddate'] = gmdate('Y-m-d', $datetime->getTimestamp());
15761576
}
15771577

15781578
$result['signedby'] = !empty($trackInfo->DeliverySignatureName) ?
@@ -1588,8 +1588,8 @@ private function processTrackingDetails(\stdClass $trackInfo)
15881588

15891589
$datetime = $this->getDeliveryDateTime($trackInfo);
15901590
if ($datetime) {
1591-
$result['deliverydate'] = $datetime->format('Y-m-d');
1592-
$result['deliverytime'] = $datetime->format('H:i:s');
1591+
$result['deliverydate'] = gmdate('Y-m-d', $datetime->getTimestamp());
1592+
$result['deliverytime'] = gmdate('H:i:s', $datetime->getTimestamp());
15931593
}
15941594

15951595
$address = null;
@@ -1636,7 +1636,7 @@ private function getDeliveryDateTime(\stdClass $trackInfo)
16361636
$timestamp = $trackInfo->ActualDeliveryTimestamp;
16371637
}
16381638

1639-
return $timestamp ? \DateTime::createFromFormat(\DateTime::ISO8601, $timestamp) : null;
1639+
return $timestamp ? $this->parseDate($timestamp) : null;
16401640
}
16411641

16421642
/**
@@ -1685,10 +1685,10 @@ private function processTrackDetailsEvents(array $events)
16851685
'deliverylocation' => null
16861686
];
16871687

1688-
if (!empty($event->Timestamp)) {
1689-
$datetime = \DateTime::createFromFormat(\DateTime::ISO8601, $event->Timestamp);
1690-
$item['deliverydate'] = $datetime->format('Y-m-d');
1691-
$item['deliverytime'] = $datetime->format('H:i:s');
1688+
$datetime = $this->parseDate(!empty($event->Timestamp) ? $event->Timestamp : null);
1689+
if ($datetime) {
1690+
$item['deliverydate'] = gmdate('Y-m-d', $datetime->getTimestamp());
1691+
$item['deliverytime'] = gmdate('H:i:s', $datetime->getTimestamp());
16921692
}
16931693

16941694
if (!empty($event->Address)) {
@@ -1716,4 +1716,30 @@ private function appendTrackingError($trackingValue, $errorMessage)
17161716
$result = $this->getResult();
17171717
$result->append($error);
17181718
}
1719+
1720+
/**
1721+
* Parses datetime string from FedEx response.
1722+
* According to FedEx API, datetime string should be in \DateTime::ATOM format, but
1723+
* sometimes FedEx returns datetime without timezone and in that case timezone will be set as UTC.
1724+
*
1725+
* @param string $timestamp
1726+
* @return bool|\DateTime
1727+
*/
1728+
private function parseDate($timestamp)
1729+
{
1730+
if ($timestamp === null) {
1731+
return false;
1732+
}
1733+
$formats = [\DateTime::ATOM, 'Y-m-d\TH:i:s'];
1734+
foreach ($formats as $format) {
1735+
// set UTC timezone for a case if timestamp does not contain any timezone
1736+
$utcTimezone = new \DateTimeZone('UTC');
1737+
$dateTime = \DateTime::createFromFormat($format, $timestamp, $utcTimezone);
1738+
if ($dateTime !== false) {
1739+
return $dateTime;
1740+
}
1741+
}
1742+
1743+
return false;
1744+
}
17191745
}

app/code/Magento/Fedex/Test/Unit/Model/CarrierTest.php

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -393,8 +393,12 @@ public function testGetTrackingErrorResponse()
393393

394394
/**
395395
* @covers \Magento\Fedex\Model\Carrier::getTracking
396+
* @param string $shipTimeStamp
397+
* @param string $expectedDate
398+
* @param string $expectedTime
399+
* @dataProvider shipDateDataProvider
396400
*/
397-
public function testGetTracking()
401+
public function testGetTracking($shipTimeStamp, $expectedDate, $expectedTime)
398402
{
399403
$tracking = '123456789012';
400404

@@ -404,15 +408,15 @@ public function testGetTracking()
404408
$response->CompletedTrackDetails = new \stdClass();
405409

406410
$trackDetails = new \stdClass();
407-
$trackDetails->ShipTimestamp = '2016-08-05T14:06:35+00:00';
411+
$trackDetails->ShipTimestamp = $shipTimeStamp;
408412
$trackDetails->DeliverySignatureName = 'signature';
409413

410414
$trackDetails->StatusDetail = new \stdClass();
411415
$trackDetails->StatusDetail->Description = 'SUCCESS';
412416

413417
$trackDetails->Service = new \stdClass();
414418
$trackDetails->Service->Description = 'ground';
415-
$trackDetails->EstimatedDeliveryTimestamp = '2016-08-10T10:20:26+00:00';
419+
$trackDetails->EstimatedDeliveryTimestamp = $shipTimeStamp;
416420

417421
$trackDetails->EstimatedDeliveryAddress = new \stdClass();
418422
$trackDetails->EstimatedDeliveryAddress->City = 'Culver City';
@@ -444,25 +448,44 @@ public function testGetTracking()
444448
'signedby',
445449
'status',
446450
'service',
447-
'shippeddate',
448-
'deliverydate',
449-
'deliverytime',
450451
'deliverylocation',
451452
'weight',
452453
];
453454
array_walk($fields, function ($field) use ($current) {
454455
static::assertNotEmpty($current[$field]);
455456
});
456457

457-
static::assertEquals('2016-08-10', $current['deliverydate']);
458-
static::assertEquals('10:20:26', $current['deliverytime']);
459-
static::assertEquals('2016-08-05', $current['shippeddate']);
458+
static::assertEquals($expectedDate, $current['deliverydate']);
459+
static::assertEquals($expectedTime, $current['deliverytime']);
460+
static::assertEquals($expectedDate, $current['shippeddate']);
461+
}
462+
463+
/**
464+
* Gets list of variations for testing ship date.
465+
*
466+
* @return array
467+
*/
468+
public function shipDateDataProvider()
469+
{
470+
return [
471+
['shipTimestamp' => '2016-08-05T14:06:35+01:00', 'expectedDate' => '2016-08-05', '13:06:35'],
472+
['shipTimestamp' => '2016-08-05T02:06:35+03:00', 'expectedDate' => '2016-08-04', '23:06:35'],
473+
['shipTimestamp' => '2016-08-05T14:06:35', 'expectedDate' => '2016-08-05', '14:06:35'],
474+
['shipTimestamp' => '2016-08-05 14:06:35', 'expectedDate' => null, null],
475+
['shipTimestamp' => '2016-08-05 14:06:35+00:00', 'expectedDate' => null, null],
476+
['shipTimestamp' => '2016-08-05', 'expectedDate' => null, null],
477+
['shipTimestamp' => '2016/08/05', 'expectedDate' => null, null],
478+
];
460479
}
461480

462481
/**
463482
* @covers \Magento\Fedex\Model\Carrier::getTracking
483+
* @param string $shipTimeStamp
484+
* @param string $expectedDate
485+
* @param string $expectedTime
486+
* @dataProvider shipDateDataProvider
464487
*/
465-
public function testGetTrackingWithEvents()
488+
public function testGetTrackingWithEvents($shipTimeStamp, $expectedDate, $expectedTime)
466489
{
467490
$tracking = '123456789012';
468491

@@ -473,7 +496,7 @@ public function testGetTrackingWithEvents()
473496

474497
$event = new \stdClass();
475498
$event->EventDescription = 'Test';
476-
$event->Timestamp = '2016-08-05T19:14:53+00:00';
499+
$event->Timestamp = $shipTimeStamp;
477500
$event->Address = new \stdClass();
478501

479502
$event->Address->City = 'Culver City';
@@ -504,12 +527,12 @@ public function testGetTrackingWithEvents()
504527
static::assertEquals(1, count($current['progressdetail']));
505528

506529
$event = $current['progressdetail'][0];
507-
$fields = ['activity', 'deliverydate', 'deliverytime', 'deliverylocation'];
530+
$fields = ['activity', 'deliverylocation'];
508531
array_walk($fields, function ($field) use ($event) {
509532
static::assertNotEmpty($event[$field]);
510533
});
511-
static::assertEquals('2016-08-05', $event['deliverydate']);
512-
static::assertEquals('19:14:53', $event['deliverytime']);
534+
static::assertEquals($expectedDate, $event['deliverydate']);
535+
static::assertEquals($expectedTime, $event['deliverytime']);
513536
}
514537

515538
/**

app/code/Magento/Payment/view/base/web/js/model/credit-card-validation/validator.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
} else {
2020
factory(jQuery);
2121
}
22-
}(function ($, cvvValidator, creditCardNumberValidator, expirationDateValidator, monthValidator, creditCardData) {
22+
}(function ($, cvvValidator, creditCardNumberValidator, yearValidator, monthValidator, creditCardData) {
2323
'use strict';
2424

2525
$.each({
@@ -49,6 +49,7 @@
4949

5050
/**
5151
* Validate credit card number based on mod 10
52+
*
5253
* @param {*} number - credit card number
5354
* @return {Boolean}
5455
*/
@@ -60,8 +61,9 @@
6061
'validate-card-date': [
6162

6263
/**
63-
* Validate credit card number based on mod 10
64-
* @param {*} date - month
64+
* Validate credit card expiration month
65+
*
66+
* @param {String} date - month
6567
* @return {Boolean}
6668
*/
6769
function (date) {
@@ -72,8 +74,9 @@
7274
'validate-card-cvv': [
7375

7476
/**
75-
* Validate credit card number based on mod 10
76-
* @param {*} cvv - month
77+
* Validate cvv
78+
*
79+
* @param {String} cvv - card verification value
7780
* @return {Boolean}
7881
*/
7982
function (cvv) {
@@ -86,12 +89,13 @@
8689
'validate-card-year': [
8790

8891
/**
89-
* Validate credit card number based on mod 10
90-
* @param {*} date - month
92+
* Validate credit card expiration year
93+
*
94+
* @param {String} date - year
9195
* @return {Boolean}
9296
*/
9397
function (date) {
94-
return monthValidator(date).isValid;
98+
return yearValidator(date).isValid;
9599
},
96100
$.mage.__('Incorrect credit card expiration year.')
97101
]

app/code/Magento/Quote/Model/ResourceModel/Quote.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,14 +242,17 @@ public function substractProductFromQuotes($product)
242242
}
243243
$connection = $this->getConnection();
244244
$subSelect = $connection->select();
245+
$conditionCheck = $connection->quoteIdentifier('q.items_count') . " > 0";
246+
$conditionTrue = $connection->quoteIdentifier('q.items_count') . ' - 1';
247+
$ifSql = "IF (" . $conditionCheck . "," . $conditionTrue . ", 0)";
245248

246249
$subSelect->from(
247250
false,
248251
[
249252
'items_qty' => new \Zend_Db_Expr(
250253
$connection->quoteIdentifier('q.items_qty') . ' - ' . $connection->quoteIdentifier('qi.qty')
251254
),
252-
'items_count' => new \Zend_Db_Expr($connection->quoteIdentifier('q.items_count') . ' - 1')
255+
'items_count' => new \Zend_Db_Expr($ifSql)
253256
]
254257
)->join(
255258
['qi' => $this->getTable('quote_item')],

app/code/Magento/Shipping/view/frontend/templates/tracking/details.phtml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
/** @var $block \Magento\Framework\View\Element\Template */
1010

11+
$parentBlock = $block->getParentBlock();
1112
$track = $block->getData('track');
1213
$email = $block->getData('storeSupportEmail');
1314
$fields = [
@@ -18,14 +19,15 @@ $fields = [
1819
'Service Type' => 'getService',
1920
'Weight' => 'getWeight',
2021
];
22+
$number = is_object($track) ? $track->getTracking() : $track['number'];
2123
?>
22-
<table class="data table order tracking" id="tracking-table-popup-<?php /* @noEscape */ echo $track->getTracking(); ?>">
24+
<table class="data table order tracking" id="tracking-table-popup-<?php /* @noEscape */ echo $number; ?>">
2325
<caption class="table-caption"><?php echo $block->escapeHtml(__('Order tracking')); ?></caption>
2426
<tbody>
2527
<?php if (is_object($track)): ?>
2628
<tr>
2729
<th class="col label" scope="row"><?php echo $block->escapeHtml(__('Tracking Number:')); ?></th>
28-
<td class="col value"><?php echo $block->escapeHtml($track->getTracking()); ?></td>
30+
<td class="col value"><?php echo $block->escapeHtml($number); ?></td>
2931
</tr>
3032
<?php if ($track->getCarrierTitle()): ?>
3133
<tr>
@@ -38,8 +40,8 @@ $fields = [
3840
<th class="col label" scope="row"><?php echo $block->escapeHtml(__('Error:')); ?></th>
3941
<td class="col error">
4042
<?php echo $block->escapeHtml(__('Tracking information is currently not available. Please ')); ?>
41-
<?php if ($block->getContactUsEnabled()) : ?>
42-
<a href="<?php echo $block->escapeUrl($block->getContactUs()); ?>" target="_blank"
43+
<?php if ($parentBlock->getContactUsEnabled()) : ?>
44+
<a href="<?php echo $block->escapeUrl($parentBlock->getContactUs()); ?>" target="_blank"
4345
title="<?php echo $block->escapeHtml(__('contact us')); ?>">
4446
<?php echo $block->escapeHtml(__('contact us')); ?>
4547
</a>
@@ -77,7 +79,7 @@ $fields = [
7779
<tr>
7880
<th class="col label" scope="row"><?php echo $block->escapeHtml(__('Delivered on:')); ?></th>
7981
<td class="col value">
80-
<?php /* @noEscape */ echo $block->formatDeliveryDateTime($track->getDeliverydate(), $track->getDeliverytime()); ?>
82+
<?php /* @noEscape */ echo $parentBlock->formatDeliveryDateTime($track->getDeliverydate(), $track->getDeliverytime()); ?>
8183
</td>
8284
</tr>
8385
<?php endif; ?>

app/code/Magento/Shipping/view/frontend/templates/tracking/popup.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ $results = $block->getTrackingInfo();
3131
?>
3232
<?php /* @noEscape */ echo $block->getChildHtml('shipping.tracking.details.' . $counter); ?>
3333
</div>
34-
<?php if (!empty($track->getProgressdetail())): ?>
34+
<?php if (is_object($track) && !empty($track->getProgressdetail())): ?>
3535
<?php
3636
$block->addChild('shipping.tracking.progress.'. $counter, Template::class, [
3737
'track' => $track,

0 commit comments

Comments
 (0)