Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace php date functions, Varien_Date with Carbon date library #4463

Draft
wants to merge 13 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .ddev/commands/web/phpunit
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
## Usage: phpunit
## Example: ddev phpunit

php vendor/bin/phpunit --configuration .phpunit.dist.xml --no-coverage "$@" --testdox
php vendor/bin/phpunit --configuration .phpunit.dist.xml --no-coverage "$@"
2 changes: 1 addition & 1 deletion .ddev/commands/web/phpunit-coverage-local
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
## Example: ddev phpunit-coverage-local

enable_xdebug
XDEBUG_MODE=coverage php vendor/bin/phpunit --configuration .phpunit.dist.xml --coverage-html build/coverage --testdox "$@"
XDEBUG_MODE=coverage php vendor/bin/phpunit --configuration .phpunit.dist.xml --coverage-html build/coverage "$@"
disable_xdebug
72 changes: 0 additions & 72 deletions .phpstan.dist.baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -912,12 +912,6 @@ parameters:
count: 1
path: app/code/core/Mage/Adminhtml/controllers/Sales/Order/ShipmentController.php

-
message: '#^Parameter \#1 \$order of method Mage_Sales_Model_Resource_Order_Collection_Abstract\:\:setOrderFilter\(\) expects int\|Mage_Sales_Model_Order, array\<string, mixed\> given\.$#'
identifier: argument.type
count: 1
path: app/code/core/Mage/Adminhtml/controllers/Sales/Order/ShipmentController.php

-
message: '#^Parameter \#1 \$prefix of function uniqid expects string, int\<0, max\> given\.$#'
identifier: argument.type
Expand Down Expand Up @@ -2730,24 +2724,6 @@ parameters:
count: 1
path: app/code/core/Mage/CatalogRule/Model/Observer.php

-
message: '#^Parameter \#1 \$expression of class Zend_Db_Expr constructor expects string, float given\.$#'
identifier: argument.type
count: 2
path: app/code/core/Mage/CatalogRule/Model/Resource/Rule.php

-
message: '#^Parameter \#1 \$expression of class Zend_Db_Expr constructor expects string, int given\.$#'
identifier: argument.type
count: 3
path: app/code/core/Mage/CatalogRule/Model/Resource/Rule.php

-
message: '#^Parameter \#1 \$expression of class Zend_Db_Expr constructor expects string, int\<0, 86398\>\|int\<86400, max\> given\.$#'
identifier: argument.type
count: 1
path: app/code/core/Mage/CatalogRule/Model/Resource/Rule.php

-
message: '#^Variable \$indexAlias might not be defined\.$#'
identifier: variable.undefined
Expand Down Expand Up @@ -3252,24 +3228,6 @@ parameters:
count: 1
path: app/code/core/Mage/Core/Model/Cookie.php

-
message: '#^Binary operation "\+" between string and string results in an error\.$#'
identifier: binaryOp.invalid
count: 1
path: app/code/core/Mage/Core/Model/Date.php

-
message: '#^Binary operation "\-" between string and string results in an error\.$#'
identifier: binaryOp.invalid
count: 1
path: app/code/core/Mage/Core/Model/Date.php

-
message: '#^Property Mage_Core_Model_Date\:\:\$_systemOffset is never read, only written\.$#'
identifier: property.onlyWritten
count: 1
path: app/code/core/Mage/Core/Model/Date.php

-
message: '#^Call to an undefined method Mage_Core_Model_Resource_Design\:\:validate\(\)\.$#'
identifier: method.notFound
Expand Down Expand Up @@ -5292,18 +5250,6 @@ parameters:
count: 1
path: app/code/core/Mage/Reports/Block/Product/Abstract.php

-
message: '#^Variable \$dateStart might not be defined\.$#'
identifier: variable.undefined
count: 7
path: app/code/core/Mage/Reports/Helper/Data.php

-
message: '#^Variable \$t might not be defined\.$#'
identifier: variable.undefined
count: 1
path: app/code/core/Mage/Reports/Helper/Data.php

-
message: '#^Property Mage_Reports_Model_Grouped_Collection\:\:\$_resourceCollection \(Mage_Core_Model_Resource_Db_Collection_Abstract\) does not accept Varien_Data_Collection_Db\.$#'
identifier: assign.propertyType
Expand Down Expand Up @@ -5532,12 +5478,6 @@ parameters:
count: 1
path: app/code/core/Mage/Rss/Helper/Data.php

-
message: '#^Property Mage_Rule_Model_Abstract\:\:\$_conditions \(Mage_Rule_Model_Condition_Combine\) in empty\(\) is not falsy\.$#'
identifier: empty.property
count: 1
path: app/code/core/Mage/Rule/Model/Abstract.php

-
message: '#^Parameter \#1 \$renderer of method Varien_Data_Form_Element_Abstract\:\:setRenderer\(\) expects Varien_Data_Form_Element_Renderer_Interface, Mage_Core_Block_Abstract\|false given\.$#'
identifier: argument.type
Expand Down Expand Up @@ -5652,12 +5592,6 @@ parameters:
count: 1
path: app/code/core/Mage/Sales/Block/Recurring/Profiles.php

-
message: '#^Parameter \#1 \$order of method Mage_Sales_Model_Resource_Order_Collection_Abstract\:\:setOrderFilter\(\) expects int\|Mage_Sales_Model_Order, array given\.$#'
identifier: argument.type
count: 1
path: app/code/core/Mage/Sales/Model/Api2/Order.php

-
message: '#^Parameter \#2 \$code of method Mage_Api2_Model_Resource\:\:_critical\(\) expects int\|null, string given\.$#'
identifier: argument.type
Expand Down Expand Up @@ -10092,12 +10026,6 @@ parameters:
count: 2
path: lib/Varien/Cache/Backend/Database.php

-
message: '#^Method Varien_Cache_Backend_Database\:\:touch\(\) should return bool but returns int\.$#'
identifier: return.type
count: 1
path: lib/Varien/Cache/Backend/Database.php

-
message: '#^Parameter \#2 \$chunks of method Varien_Cache_Backend_Memcached\:\:_cleanTheMess\(\) expects int, string given\.$#'
identifier: argument.type
Expand Down
4 changes: 4 additions & 0 deletions .phpunit.dist.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
<env name="NO_XHGUI" value="1"/>
</php>

<extensions>
<extension class="OpenMage\Tests\Unit\LongRunningTestAlert" />
</extensions>

<testsuites>
<testsuite name="Base">
<directory>tests/unit/Base</directory>
Expand Down
9 changes: 4 additions & 5 deletions .rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
CodeQuality\BooleanNot\SimplifyDeMorganBinaryRector::class,
CodeQuality\If_\SimplifyIfReturnBoolRector::class,
__DIR__ . '/shell/translations.php',
__DIR__ . '/shell/update-copyright.php.php'
__DIR__ . '/shell/update-copyright.php.php',
__DIR__ . '/tests/unit/Mage/Reports/Model/Resource/Report/CollectionTest.php',
])
->withRules([
CodeQuality\BooleanNot\ReplaceMultipleBooleanNotRector::class,
Expand Down Expand Up @@ -51,12 +52,10 @@
false,
false,
false,
false,
false,
true,
false,
true,
false,
false,
false,
true,
);
);
4 changes: 3 additions & 1 deletion app/code/core/Mage/Admin/Model/Acl/Assert/Time.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
* @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/

use Carbon\Carbon;

/**
* Assert time for admin acl
*
Expand All @@ -34,7 +36,7 @@ public function assert(
?Mage_Admin_Model_Acl_Resource $resource = null,
$privilege = null
) {
return $this->_isCleanTime(time());
return $this->_isCleanTime(Carbon::now()->getTimestamp());
}

/**
Expand Down
4 changes: 3 additions & 1 deletion app/code/core/Mage/Admin/Model/Resource/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
* @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/

use Carbon\Carbon;

/**
* ACL user resource
*
Expand Down Expand Up @@ -55,7 +57,7 @@ public function recordLogin(Mage_Admin_Model_User $user)
$adapter = $this->_getWriteAdapter();

$data = [
'logdate' => Varien_Date::now(),
'logdate' => Carbon::now()->format(Carbon::DEFAULT_TO_STRING_FORMAT),
'lognum' => $user->getLognum() + 1,
];

Expand Down
18 changes: 9 additions & 9 deletions app/code/core/Mage/Admin/Model/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
* @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/

use Carbon\Carbon;

/**
* Admin user model
*
Expand Down Expand Up @@ -678,7 +680,7 @@ public function changeResetPasswordLinkToken($newResetPasswordLinkToken)
throw Mage::exception('Mage_Core', Mage::helper('adminhtml')->__('Invalid password reset token.'));
}
$this->setRpToken($newResetPasswordLinkToken);
$currentDate = Varien_Date::now();
$currentDate = Carbon::now()->format(Carbon::DEFAULT_TO_STRING_FORMAT);
$this->setRpTokenCreatedAt($currentDate);

return $this;
Expand All @@ -698,17 +700,14 @@ public function isResetPasswordLinkTokenExpired()
return true;
}

$tokenExpirationPeriod = Mage::helper('admin')->getResetPasswordLinkExpirationPeriod();

$currentDate = Varien_Date::now();
$currentTimestamp = Varien_Date::toTimestamp($currentDate);
$tokenTimestamp = Varien_Date::toTimestamp($resetPasswordLinkTokenCreatedAt);
$currentTimestamp = Carbon::now();
$tokenTimestamp = Carbon::now()->setTimeFromTimeString($resetPasswordLinkTokenCreatedAt);
if ($tokenTimestamp > $currentTimestamp) {
return true;
}

$hoursDifference = floor(($currentTimestamp - $tokenTimestamp) / (60 * 60));
if ($hoursDifference >= $tokenExpirationPeriod) {
$tokenExpirationPeriod = Mage::helper('admin')->getResetPasswordLinkExpirationPeriod();
if ($currentTimestamp->diffInDays($tokenTimestamp) >= $tokenExpirationPeriod) {
return true;
}

Expand Down Expand Up @@ -737,7 +736,8 @@ public function cleanPasswordsValidationData()
*/
protected function _getDateNow($dayOnly = false)
{
return Varien_Date::now($dayOnly);
$format = $dayOnly ? Mage_Core_Helper_Date::DATE_PHP_FORMAT : Mage_Core_Helper_Date::DATETIME_PHP_FORMAT;
return Carbon::now()->format($format);
}

/**
Expand Down
6 changes: 4 additions & 2 deletions app/code/core/Mage/AdminNotification/Model/Feed.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
* @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/

use Carbon\Carbon;

/**
* AdminNotification Feed model
*
Expand Down Expand Up @@ -60,7 +62,7 @@ public function getFeedUrl()
*/
public function checkUpdate()
{
if (($this->getFrequency() + $this->getLastUpdate()) > time()) {
if (($this->getFrequency() + $this->getLastUpdate()) > Carbon::now()->getTimestamp()) {
return $this;
}

Expand Down Expand Up @@ -126,7 +128,7 @@ public function getLastUpdate()
*/
public function setLastUpdate()
{
Mage::app()->saveCache(time(), 'admin_notifications_lastcheck');
Mage::app()->saveCache(Carbon::now()->getTimestamp(), 'admin_notifications_lastcheck');
return $this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
* @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/

use Carbon\Carbon;

/**
* Customer account form block
*
Expand Down Expand Up @@ -144,7 +146,7 @@ public function getCurrentStatus()
$log = $this->getCustomerLog();
if ($log->getLogoutAt()
|| !$log->getLastVisitAt()
|| strtotime(Varien_Date::now()) - strtotime($log->getLastVisitAt()) > Mage_Log_Model_Visitor::getOnlineMinutesInterval() * 60
|| strtotime(Carbon::now()->format(Carbon::DEFAULT_TO_STRING_FORMAT)) - strtotime($log->getLastVisitAt()) > Mage_Log_Model_Visitor::getOnlineMinutesInterval() * 60
) {
return Mage::helper('customer')->__('Offline');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ protected function _prepareForm()

if ($queue->getQueueStartAt()) {
$form->getElement('date')->setValue(
Mage::app()->getLocale()->date($queue->getQueueStartAt(), Varien_Date::DATETIME_INTERNAL_FORMAT),
Mage::app()->getLocale()->date($queue->getQueueStartAt(), Mage_Core_Helper_Date::DATETIME_INTERNAL_FORMAT),
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,15 @@ protected function _prepareForm()
'label' => Mage::helper('catalogrule')->__('From Date'),
'title' => Mage::helper('catalogrule')->__('From Date'),
'image' => $this->getSkinUrl('images/grid-cal.gif'),
'input_format' => Varien_Date::DATE_INTERNAL_FORMAT,
'input_format' => Mage_Core_Helper_Date::DATE_INTERNAL_FORMAT,
'format' => $dateFormatIso,
]);
$fieldset->addField('to_date', 'date', [
'name' => 'to_date',
'label' => Mage::helper('catalogrule')->__('To Date'),
'title' => Mage::helper('catalogrule')->__('To Date'),
'image' => $this->getSkinUrl('images/grid-cal.gif'),
'input_format' => Varien_Date::DATE_INTERNAL_FORMAT,
'input_format' => Mage_Core_Helper_Date::DATE_INTERNAL_FORMAT,
'format' => $dateFormatIso,
]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,15 +200,15 @@ protected function _prepareForm()
'label' => Mage::helper('salesrule')->__('From Date'),
'title' => Mage::helper('salesrule')->__('From Date'),
'image' => $this->getSkinUrl('images/grid-cal.gif'),
'input_format' => Varien_Date::DATE_INTERNAL_FORMAT,
'input_format' => Mage_Core_Helper_Date::DATE_INTERNAL_FORMAT,
'format' => $dateFormatIso,
]);
$fieldset->addField('to_date', 'date', [
'name' => 'to_date',
'label' => Mage::helper('salesrule')->__('To Date'),
'title' => Mage::helper('salesrule')->__('To Date'),
'image' => $this->getSkinUrl('images/grid-cal.gif'),
'input_format' => Varien_Date::DATE_INTERNAL_FORMAT,
'input_format' => Mage_Core_Helper_Date::DATE_INTERNAL_FORMAT,
'format' => $dateFormatIso,
]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ protected function _toHtml()
) {
$id = "{$key}_{$idSuffix}";
$element = new Varien_Data_Form_Element_Date([
'format' => Varien_Date::DATE_INTERNAL_FORMAT, // hardcode because hardcoded values delimiter
'format' => Mage_Core_Helper_Date::DATE_INTERNAL_FORMAT, // hardcode because hardcoded values delimiter
'label' => $label,
'image' => $this->getSkinUrl('images/grid-cal.gif'),
'onchange' => "dateTimeChoose_{$idSuffix}()", // won't work through Event.observe()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
* @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/

use Carbon\Carbon;

/**
* Dashboard Year-To-Date Month and Day starts Field Renderer
*
Expand All @@ -27,7 +29,7 @@ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
$_months = [];
for ($i = 1; $i <= 12; $i++) {
$_months[$i] = Mage::app()->getLocale()
->date(mktime(0, 0, 0, $i))
->date(Carbon::now()->setHour(0)->setMinute(0)->setSecond(0)->setMonth($i))
->get(Zend_Date::MONTH_NAME);
}

Expand Down
Loading
Loading