Skip to content

Commit

Permalink
Add use for classes and use type hints on functions
Browse files Browse the repository at this point in the history
  • Loading branch information
cemag44 authored and cemag44300 committed Sep 6, 2022
1 parent a55ff50 commit 029caa8
Show file tree
Hide file tree
Showing 46 changed files with 759 additions and 464 deletions.
48 changes: 28 additions & 20 deletions Api/CustomEntityAttributeRepositoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,48 +4,56 @@

namespace Smile\CustomEntity\Api;

use Magento\Framework\Api\MetadataServiceInterface;
use Magento\Framework\Api\SearchCriteriaInterface;
use Magento\Framework\Exception\InputException as InputExceptionAlias;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\Exception\StateException;
use Smile\CustomEntity\Api\Data\CustomEntityAttributeInterface;
use Smile\CustomEntity\Api\Data\CustomEntityAttributeSearchResultsInterface;

/**
* Custom entity attribute repository interface.
*
* @api
*/
interface CustomEntityAttributeRepositoryInterface extends \Magento\Framework\Api\MetadataServiceInterface
interface CustomEntityAttributeRepositoryInterface extends MetadataServiceInterface
{
/**
* Retrieve specific attribute.
*
* @param string $attributeCode Attribute code.
*
* @return \Smile\CustomEntity\Api\Data\CustomEntityAttributeInterface
* @return CustomEntityAttributeInterface|null
*
* @throws \Magento\Framework\Exception\NoSuchEntityException
* @throws NoSuchEntityException
*/
public function get($attributeCode);
public function get(string $attributeCode): ?CustomEntityAttributeInterface;

/**
* Save attribute data.
*
* @param \Smile\CustomEntity\Api\Data\CustomEntityAttributeInterface $attribute Attribute.
* @param CustomEntityAttributeInterface $attribute Attribute.
*
* @return \Smile\CustomEntity\Api\Data\CustomEntityAttributeInterface
* @return CustomEntityAttributeInterface|null
*
* @throws \Magento\Framework\Exception\NoSuchEntityException
* @throws \Magento\Framework\Exception\InputException
* @throws \Magento\Framework\Exception\StateException
* @throws NoSuchEntityException
* @throws InputExceptionAlias
* @throws StateException
*/
public function save(\Smile\CustomEntity\Api\Data\CustomEntityAttributeInterface $attribute);
public function save(CustomEntityAttributeInterface $attribute): ?CustomEntityAttributeInterface;

/**
* Delete Attribute.
*
* @param \Smile\CustomEntity\Api\Data\CustomEntityAttributeInterface $attribute Attribute.
* @param CustomEntityAttributeInterface $attribute Attribute.
*
* @return bool True if the entity was deleted (always true)
*
* @throws \Magento\Framework\Exception\StateException
* @throws \Magento\Framework\Exception\NoSuchEntityException
* @throws StateException
* @throws NoSuchEntityException
*/
public function delete(\Smile\CustomEntity\Api\Data\CustomEntityAttributeInterface $attribute);
public function delete(CustomEntityAttributeInterface $attribute): bool;

/**
* Delete Attribute by id
Expand All @@ -54,17 +62,17 @@ public function delete(\Smile\CustomEntity\Api\Data\CustomEntityAttributeInterfa
*
* @return bool
*
* @throws \Magento\Framework\Exception\StateException
* @throws \Magento\Framework\Exception\NoSuchEntityException
* @throws StateException
* @throws NoSuchEntityException
*/
public function deleteById($attributeCode);
public function deleteById(string $attributeCode): bool;

/**
* Retrieve all attributes for entity type.
*
* @param \Magento\Framework\Api\SearchCriteriaInterface $searchCriteria Search criteria.
* @param SearchCriteriaInterface $searchCriteria Search criteria.
*
* @return \Smile\CustomEntity\Api\Data\CustomEntityAttributeSearchResultsInterface
* @return CustomEntityAttributeSearchResultsInterface|null
*/
public function getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria);
public function getList(SearchCriteriaInterface $searchCriteria): ?CustomEntityAttributeSearchResultsInterface;
}
45 changes: 27 additions & 18 deletions Api/CustomEntityRepositoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@

namespace Smile\CustomEntity\Api;

use Magento\Framework\Api\SearchCriteriaInterface;
use Magento\Framework\Api\SearchResults;
use Magento\Framework\Exception\CouldNotSaveException;
use Magento\Framework\Exception\InputException;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\Exception\StateException;
use Smile\CustomEntity\Api\Data\CustomEntityInterface;
use Smile\CustomEntity\Api\Data\CustomEntitySearchResultsInterface;

/**
* Custom entity repository interface.
*
Expand All @@ -14,15 +23,15 @@ interface CustomEntityRepositoryInterface
/**
* Save a custom entity.
*
* @param \Smile\CustomEntity\Api\Data\CustomEntityInterface $entity Saved entity.
* @param CustomEntityInterface|null $entity Saved entity.
*
* @return \\Smile\CustomEntity\Api\Data\CustomEntityInterface
* @return CustomEntityInterface|null
*
* @throws \Magento\Framework\Exception\InputException
* @throws \Magento\Framework\Exception\StateException
* @throws \Magento\Framework\Exception\CouldNotSaveException
* @throws InputException
* @throws StateException
* @throws CouldNotSaveException
*/
public function save(\Smile\CustomEntity\Api\Data\CustomEntityInterface $entity);
public function save(?CustomEntityInterface $entity): ?CustomEntityInterface;

/**
* Get custom entity by id.
Expand All @@ -31,23 +40,23 @@ public function save(\Smile\CustomEntity\Api\Data\CustomEntityInterface $entity)
* @param int|null $storeId Store Id.
* @param bool $forceReload Force reload the entity..
*
* @return \Smile\CustomEntity\Api\Data\CustomEntityInterface
* @return CustomEntityInterface|null
*
* @throws \Magento\Framework\Exception\NoSuchEntityException
* @throws NoSuchEntityException
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
*/
public function get($entityId, $storeId = null, $forceReload = false);
public function get(int $entityId, ?int $storeId = null, bool $forceReload = false): ?CustomEntityInterface;

/**
* Delete custom entity.
*
* @param \Smile\CustomEntity\Api\Data\CustomEntityInterface $entity Deleted entity.
* @param CustomEntityInterface $entity Deleted entity.
*
* @return bool Will returned True if deleted
*
* @throws \Magento\Framework\Exception\StateException
* @throws StateException
*/
public function delete(\Smile\CustomEntity\Api\Data\CustomEntityInterface $entity);
public function delete(CustomEntityInterface $entity): bool;

/**
* Delete custom entity by id.
Expand All @@ -56,17 +65,17 @@ public function delete(\Smile\CustomEntity\Api\Data\CustomEntityInterface $entit
*
* @return bool Will returned True if deleted
*
* @throws \Magento\Framework\Exception\NoSuchEntityException
* @throws \Magento\Framework\Exception\StateException
* @throws NoSuchEntityException
* @throws StateException
*/
public function deleteById($entityId);
public function deleteById(int $entityId): bool;

/**
* Get custom entity list.
*
* @param \Magento\Framework\Api\SearchCriteriaInterface $searchCriteria Search criteria.
* @param SearchCriteriaInterface $searchCriteria Search criteria.
*
* @return \Smile\CustomEntity\Api\Data\CustomEntitySearchResultsInterface
* @return CustomEntitySearchResultsInterface|SearchResults
*/
public function getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria);
public function getList(SearchCriteriaInterface $searchCriteria);
}
5 changes: 4 additions & 1 deletion Api/Data/CustomEntityAttributeInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@

namespace Smile\CustomEntity\Api\Data;

use Smile\ScopedEav\Api\Data\AttributeInterface;

/**
* Custom entity attribute interface.
*
* @api
*/
interface CustomEntityAttributeInterface extends \Smile\ScopedEav\Api\Data\AttributeInterface
interface CustomEntityAttributeInterface extends AttributeInterface
{
/**
* Entity code. Can be used as part of method name for entity processing.
* @var string
*/
const ENTITY_TYPE_CODE = 'smile_custom_entity';
}
12 changes: 7 additions & 5 deletions Api/Data/CustomEntityAttributeSearchResultsInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,28 @@

namespace Smile\CustomEntity\Api\Data;

use Magento\Framework\Api\SearchResultsInterface;

/**
* Custom entity attribute search result interface.
*
* @api
*/
interface CustomEntityAttributeSearchResultsInterface extends \Magento\Framework\Api\SearchResultsInterface
interface CustomEntityAttributeSearchResultsInterface extends SearchResultsInterface
{
/**
* Get attributes list.
*
* @return \Smile\CustomEntity\Api\Data\CustomEntityAttributeInterface[]
* @return CustomEntityAttributeInterface[]|null
*/
public function getItems();
public function getItems(): ?array;

/**
* Set attributes list.
*
* @param \Smile\CustomEntity\Api\Data\CustomEntityAttributeInterface[] $items Items.
* @param CustomEntityAttributeInterface[] $items Items.
*
* @return $this
*/
public function setItems(array $items);
public function setItems(array $items): self;
}
18 changes: 9 additions & 9 deletions Api/Data/CustomEntityInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ interface CustomEntityInterface extends \Smile\ScopedEav\Api\Data\EntityInterfac
/**
* Returns custom entity url key.
*
* @return string
* @return string|null
*/
public function getUrlKey();
public function getUrlKey(): ?string;

/**
* Set custom entity url key.
Expand All @@ -38,27 +38,27 @@ public function getUrlKey();
*
* @return $this
*/
public function setUrlKey($urlKey);
public function setUrlKey(string $urlKey): self;

/**
* Returns custom entity url path.
*
* @return string
* @return string|null
*/
public function getUrlPath();
public function getUrlPath(): ?string;

/**
* Retrieve existing extension attributes object or create a new one.
*
* @return \Smile\CustomEntity\Api\Data\CustomEntityExtensionInterface|null
* @return CustomEntityExtensionInterface|null
*/
public function getExtensionAttributes();
public function getExtensionAttributes(): ?CustomEntityExtensionInterface;

/**
* Set an extension attributes object.
*
* @param \Smile\CustomEntity\Api\Data\CustomEntityExtensionInterface $extensionAttributes Extension attributes.
* @param CustomEntityExtensionInterface $extensionAttributes Extension attributes.
* @return $this
*/
public function setExtensionAttributes(\Smile\CustomEntity\Api\Data\CustomEntityExtensionInterface $extensionAttributes);
public function setExtensionAttributes(CustomEntityExtensionInterface $extensionAttributes): self;
}
6 changes: 3 additions & 3 deletions Api/Data/CustomEntitySearchResultsInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ interface CustomEntitySearchResultsInterface extends SearchResultsInterface
/**
* Get custom entities list.
*
* @return CustomEntityInterface[]
* @return CustomEntityInterface[]|null
*/
public function getItems();
public function getItems(): ?array;

/**
* Set custom entities list.
Expand All @@ -27,5 +27,5 @@ public function getItems();
*
* @return $this
*/
public function setItems(array $items);
public function setItems(array $items): self;
}
33 changes: 20 additions & 13 deletions Block/Adminhtml/Attribute/Edit/Tab/Front.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,17 @@

namespace Smile\CustomEntity\Block\Adminhtml\Attribute\Edit\Tab;

use Magento\Backend\Block\Template\Context;
use Magento\Backend\Block\Widget\Form\Generic;
use Magento\Config\Model\Config\Source\Yesno;
use Magento\Framework\Data\FormFactory;
use Magento\Framework\Registry;
use Smile\CustomEntity\Api\Data\CustomEntityAttributeInterface;

/**
* Custom entity attribute store front properties form.
* Custom entity attribute storefront properties form.
*/
class Front extends \Magento\Backend\Block\Widget\Form\Generic
class Front extends Generic
{
/**
* @var Yesno
Expand All @@ -17,17 +24,17 @@ class Front extends \Magento\Backend\Block\Widget\Form\Generic
/**
* Constructor.
*
* @param \Magento\Backend\Block\Template\Context $context Context.
* @param \Magento\Framework\Registry $registry Registry.
* @param \Magento\Framework\Data\FormFactory $formFactory Form factory.
* @param \Magento\Config\Model\Config\Source\Yesno $yesNo Yes/No source model
* @param array $data Additional data.
* @param Context $context Context.
* @param Registry $registry Registry.
* @param FormFactory $formFactory Form factory.
* @param Yesno $yesNo Yes/No source model
* @param array $data Additional data.
*/
public function __construct(
\Magento\Backend\Block\Template\Context $context,
\Magento\Framework\Registry $registry,
\Magento\Framework\Data\FormFactory $formFactory,
\Magento\Config\Model\Config\Source\Yesno $yesNo,
Context $context,
Registry $registry,
FormFactory $formFactory,
Yesno $yesNo,
array $data = []
) {
parent::__construct($context, $registry, $formFactory, $data);
Expand Down Expand Up @@ -73,9 +80,9 @@ protected function _prepareForm()
/**
* Retrieve attribute object from registry
*
* @return \Smile\CustomEntity\Api\Data\CustomEntityAttributeInterface
* @return CustomEntityAttributeInterface|null
*/
private function getAttributeObject()
private function getAttributeObject(): ?CustomEntityAttributeInterface
{
return $this->_coreRegistry->registry('entity_attribute');
}
Expand Down
5 changes: 3 additions & 2 deletions Block/Adminhtml/Entity.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@
namespace Smile\CustomEntity\Block\Adminhtml;

use Smile\CustomEntity\Api\Data\CustomEntityInterface;
use Smile\ScopedEav\Block\Adminhtml\AbstractEntity;

/**
* Custom entity listing main container.
*/
class Entity extends \Smile\ScopedEav\Block\Adminhtml\AbstractEntity
class Entity extends AbstractEntity
{
/**
* {@inheritDoc}
*/
protected function getEntityTypeCode()
protected function getEntityTypeCode(): string
{
return CustomEntityInterface::ENTITY;
}
Expand Down
Loading

0 comments on commit 029caa8

Please sign in to comment.