Skip to content

Commit

Permalink
Merge pull request #192 from magento-engcom/99_strict_typing
Browse files Browse the repository at this point in the history
#99 - Add Strict Typing
  • Loading branch information
Valeriy Nayda authored Dec 8, 2017
2 parents a33661f + 0787add commit 549f725
Show file tree
Hide file tree
Showing 123 changed files with 250 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ public function __construct(
*/
public function execute(): ResultInterface
{
$sourceId = $this->getRequest()->getParam(SourceInterface::SOURCE_ID);
$sourceId = (int)$this->getRequest()->getParam(SourceInterface::SOURCE_ID);
try {
$source = $this->sourceRepository->get((int)$sourceId);
$source = $this->sourceRepository->get($sourceId);

/** @var Page $result */
$result = $this->resultFactory->create(ResultFactory::TYPE_PAGE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,28 +66,27 @@ public function execute(): ResultInterface
if ($request->isXmlHttpRequest() && $request->isPost() && $requestData) {
foreach ($requestData as $itemData) {
try {
$source = $this->sourceRepository->get(
$itemData[SourceInterface::SOURCE_ID]
);
$sourceId = (int)$itemData[SourceInterface::SOURCE_ID];
$source = $this->sourceRepository->get($sourceId);
$this->dataObjectHelper->populateWithArray($source, $itemData, SourceInterface::class);
$this->sourceRepository->save($source);
} catch (NoSuchEntityException $e) {
$errorMessages[] = __(
'[ID: %value] The Source does not exist.',
['value' => $itemData[SourceInterface::SOURCE_ID]]
['value' => $sourceId]
);
} catch (ValidationException $e) {
foreach ($e->getErrors() as $localizedError) {
$errorMessages[] = __('[ID: %value] %message', [
'value' => $itemData[SourceInterface::SOURCE_ID],
'value' => $sourceId,
'message' => $localizedError->getMessage()
]);
}
} catch (CouldNotSaveException $e) {
$errorMessages[] = __(
'[ID: %value] %message',
[
'value' => $itemData[SourceInterface::SOURCE_ID],
'value' => $sourceId,
'message' => $e->getMessage()
]
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public function execute(): ResultInterface
}

try {
$stockId = (int)$stockId;
$this->stockRepository->deleteById($stockId);
$this->messageManager->addSuccessMessage(__('The Stock has been deleted.'));
$resultRedirect->setPath('*/*');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ public function __construct(
*/
public function execute(): ResultInterface
{
$stockId = $this->getRequest()->getParam(StockInterface::STOCK_ID);
$stockId = (int)$this->getRequest()->getParam(StockInterface::STOCK_ID);
try {
$stock = $this->stockRepository->get((int)$stockId);
$stock = $this->stockRepository->get($stockId);

/** @var Page $result */
$result = $this->resultFactory->create(ResultFactory::TYPE_PAGE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,26 +66,25 @@ public function execute(): ResultInterface
if ($request->isXmlHttpRequest() && $request->isPost() && $requestData) {
foreach ($requestData as $itemData) {
try {
$stock = $this->stockRepository->get(
$itemData[StockInterface::STOCK_ID]
);
$stockId = (int)$itemData[StockInterface::STOCK_ID];
$stock = $this->stockRepository->get($stockId);
$this->dataObjectHelper->populateWithArray($stock, $itemData, StockInterface::class);
$this->stockRepository->save($stock);
} catch (NoSuchEntityException $e) {
$errorMessages[] = __(
'[ID: %value] The Stock does not exist.',
['value' => $itemData[StockInterface::STOCK_ID]]
['value' => $stockId]
);
} catch (ValidationException $e) {
foreach ($e->getErrors() as $localizedError) {
$errorMessages[] = __('[ID: %value] %message', [
'value' => $itemData[StockInterface::STOCK_ID],
'value' => $stockId,
'message' => $localizedError->getMessage()
]);
}
} catch (CouldNotSaveException $e) {
$errorMessages[] = __('[ID: %value] %message', [
'value' => $itemData[StockInterface::STOCK_ID],
'value' => $stockId,
'message' => $e->getMessage()
]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public function execute(): ResultInterface
$deletedItemsCount = 0;
foreach ($this->massActionFilter->getIds() as $id) {
try {
$id = (int)$id;
$this->stockRepository->deleteById($id);
$deletedItemsCount++;
} catch (CouldNotDeleteException $e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Inventory\Controller\Adminhtml\Stock;

use Magento\Framework\Exception\InputException;
Expand Down Expand Up @@ -66,12 +68,12 @@ public function __construct(
}

/**
* @param string $stockId
* @param int $stockId
* @param array $stockSourceLinksData
* @return void
* @throws InputException
*/
public function process($stockId, array $stockSourceLinksData)
public function process(int $stockId, array $stockSourceLinksData)
{
$this->validateStockSourceData($stockSourceLinksData);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Inventory\Model\OptionSource;

use Magento\Framework\Data\OptionSourceInterface;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Inventory\Model\OptionSource;

use Magento\Directory\Model\ResourceModel\Region\CollectionFactory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Inventory\Model\OptionSource;

use Magento\Framework\Data\OptionSourceInterface;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ public function build(): ReservationInterface
return $reservation;
}

/**
* @return ValidationResult
*/
private function validate()
{
$errors = [];
Expand All @@ -153,7 +156,8 @@ private function validate()
}

/**
* Used to clean state after object creation.
* Used to clean state after object creation
* @return void
*/
private function reset()
{
Expand All @@ -170,7 +174,7 @@ private function reset()
* @param array $array
* @return array
*/
private function convertArrayKeysFromSnakeToCamelCase(array $array)
private function convertArrayKeysFromSnakeToCamelCase(array $array): array
{
$convertedArrayKeys = $this->snakeToCamelCaseConverter->convert(array_keys($array));
return array_combine($convertedArrayKeys, array_values($array));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Inventory\Model\ResourceModel;

use Magento\Framework\Exception\LocalizedException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ class ReservationCleanup implements ReservationCleanupInterface
private $groupConcatMaxLen;

/**
* ReservationCleanup constructor.
*
* @param ResourceConnection $resource
* @param int $groupConcatMaxLen
*/
Expand Down
2 changes: 2 additions & 0 deletions app/code/Magento/Inventory/Model/ResourceModel/Source.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Inventory\Model\ResourceModel;

use Exception;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Inventory\Model\ResourceModel\Source;

use Magento\Framework\Data\Collection\Db\FetchStrategyInterface;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Inventory\Model\ResourceModel;

use Magento\Framework\Model\ResourceModel\Db\AbstractDb;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Inventory\Model\ResourceModel\SourceCarrierLink;

use Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection;
Expand Down
2 changes: 2 additions & 0 deletions app/code/Magento/Inventory/Model/ResourceModel/SourceItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Inventory\Model\ResourceModel;

use Magento\Framework\Model\ResourceModel\Db\AbstractDb;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Inventory\Model\ResourceModel\SourceItem;

use Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Inventory\Model\ResourceModel\SourceItem;

use Magento\Framework\App\ResourceConnection;
Expand Down
2 changes: 2 additions & 0 deletions app/code/Magento/Inventory/Model/ResourceModel/Stock.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Inventory\Model\ResourceModel;

use Magento\Framework\Model\ResourceModel\Db\AbstractDb;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Inventory\Model\ResourceModel\Stock;

use Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Inventory\Model\ResourceModel;

use Magento\Framework\Model\ResourceModel\Db\AbstractDb;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Inventory\Model\ResourceModel\StockSourceLink;

use Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Inventory\Model\ResourceModel\StockSourceLink;

use Magento\Framework\App\ResourceConnection;
Expand Down Expand Up @@ -34,7 +36,7 @@ public function __construct(
* @param int $stockId
* @return void
*/
public function execute(array $sourceIds, $stockId)
public function execute(array $sourceIds, int $stockId)
{
if (!count($sourceIds)) {
return;
Expand Down
2 changes: 2 additions & 0 deletions app/code/Magento/Inventory/Model/Source.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Inventory\Model;

use Magento\Framework\Model\AbstractExtensibleModel;
Expand Down
2 changes: 2 additions & 0 deletions app/code/Magento/Inventory/Model/Source/Command/Get.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Inventory\Model\Source\Command;

use Magento\Framework\Exception\NoSuchEntityException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Inventory\Model\Source\Command;

use Magento\Framework\Exception\NoSuchEntityException;
Expand Down
2 changes: 2 additions & 0 deletions app/code/Magento/Inventory/Model/Source/Command/GetList.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Inventory\Model\Source\Command;

use Magento\Framework\Api\SearchCriteria\CollectionProcessorInterface;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Inventory\Model\Source\Command;

use Magento\Framework\Api\SearchCriteriaInterface;
Expand Down
4 changes: 3 additions & 1 deletion app/code/Magento/Inventory/Model/Source/Command/Save.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Inventory\Model\Source\Command;

use Magento\Framework\Exception\CouldNotSaveException;
Expand Down Expand Up @@ -60,7 +62,7 @@ public function execute(SourceInterface $source): int

try {
$this->sourceResource->save($source);
return $source->getSourceId();
return (int)$source->getSourceId();
} catch (\Exception $e) {
$this->logger->error($e->getMessage());
throw new CouldNotSaveException(__('Could not save Source'), $e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Inventory\Model\Source\Command;

use Magento\Framework\Exception\CouldNotSaveException;
Expand Down
Loading

0 comments on commit 549f725

Please sign in to comment.