88
99namespace Mygento \Shipment \Model ;
1010
11+ use Magento \Framework \Api \SearchCriteria \CollectionProcessorInterface ;
12+ use Magento \Framework \Api \SearchCriteriaInterface ;
13+ use Magento \Framework \Exception \CouldNotDeleteException ;
14+ use Magento \Framework \Exception \CouldNotSaveException ;
15+ use Magento \Framework \Exception \NoSuchEntityException ;
16+ use Mygento \Shipment \Api \Data \PointInterface ;
17+ use Mygento \Shipment \Api \Data \PointInterfaceFactory ;
18+ use Mygento \Shipment \Api \Data \PointSearchResultsInterface ;
19+ use Mygento \Shipment \Api \Data \PointSearchResultsInterfaceFactory ;
20+ use Mygento \Shipment \Api \PointRepositoryInterface ;
21+ use Mygento \Shipment \Model \ResourceModel \Point \CollectionFactory ;
22+
1123/**
1224 * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1325 */
14- class PointRepository implements \ Mygento \ Shipment \ Api \ PointRepositoryInterface
26+ class PointRepository implements PointRepositoryInterface
1527{
16- /** @var \Mygento\Shipment\Model\ResourceModel\Point */
17- private $ resource ;
18-
19- /** @var \Mygento\Shipment\Model\ResourceModel\Point\CollectionFactory */
20- private $ collectionFactory ;
21-
22- /** @var \Mygento\Shipment\Api\Data\PointInterfaceFactory */
23- private $ entityFactory ;
24-
25- /** @var \Mygento\Shipment\Api\Data\PointSearchResultsInterfaceFactory */
26- private $ searchResultsFactory ;
27-
28- /**
29- * @var \Magento\Framework\Api\SearchCriteria\CollectionProcessorInterface
30- */
31- private $ collectionProcessor ;
32-
33- /**
34- * PointRepository constructor.
35- * @param ResourceModel\Point $resource
36- * @param ResourceModel\Point\CollectionFactory $collectionFactory
37- * @param \Mygento\Shipment\Api\Data\PointInterfaceFactory $entityFactory
38- * @param \Mygento\Shipment\Api\Data\PointSearchResultsInterfaceFactory $searchResultsFactory
39- * @param \Magento\Framework\Api\SearchCriteria\CollectionProcessorInterface|null $collectionProcessor
40- */
4128 public function __construct (
42- ResourceModel \Point $ resource ,
43- ResourceModel \Point \CollectionFactory $ collectionFactory ,
44- \Mygento \Shipment \Api \Data \PointInterfaceFactory $ entityFactory ,
45- \Mygento \Shipment \Api \Data \PointSearchResultsInterfaceFactory $ searchResultsFactory ,
46- \Magento \Framework \Api \SearchCriteria \CollectionProcessorInterface $ collectionProcessor = null ,
47- ) {
48- $ this ->resource = $ resource ;
49- $ this ->collectionFactory = $ collectionFactory ;
50- $ this ->entityFactory = $ entityFactory ;
51- $ this ->searchResultsFactory = $ searchResultsFactory ;
52- $ this ->collectionProcessor = $ collectionProcessor ;
53- }
29+ private ResourceModel \Point $ resource ,
30+ private CollectionFactory $ collectionFactory ,
31+ private PointInterfaceFactory $ entityFactory ,
32+ private PointSearchResultsInterfaceFactory $ searchResultsFactory ,
33+ private CollectionProcessorInterface $ collectionProcessor ,
34+ ) {}
5435
5536 /**
56- * @param int $entityId
57- * @throws \Magento\Framework\Exception\NoSuchEntityException
58- * @return \Mygento\Shipment\Api\Data\PointInterface
37+ * @throws NoSuchEntityException
5938 */
60- public function getById ($ entityId )
39+ public function getById (int $ entityId ): PointInterface
6140 {
6241 $ entity = $ this ->entityFactory ->create ();
6342 $ this ->resource ->load ($ entity , $ entityId );
6443 if (!$ entity ->getId ()) {
65- throw new \ Magento \ Framework \ Exception \ NoSuchEntityException (
66- __ ('Shipment Point with id "%1" does not exist. ' , $ entityId ),
44+ throw new NoSuchEntityException (
45+ __ ('A Shipment Point with id "%1" does not exist ' , $ entityId ),
6746 );
6847 }
6948
7049 return $ entity ;
7150 }
7251
7352 /**
74- * @param \Mygento\Shipment\Api\Data\PointInterface $entity
75- * @throws \Magento\Framework\Exception\CouldNotSaveException
76- * @return \Mygento\Shipment\Api\Data\PointInterface
53+ * @throws CouldNotSaveException
7754 */
78- public function save (\ Mygento \ Shipment \ Api \ Data \ PointInterface $ entity )
55+ public function save (PointInterface $ entity ): PointInterface
7956 {
8057 try {
8158 $ this ->resource ->save ($ entity );
8259 } catch (\Exception $ exception ) {
83- throw new \Magento \Framework \Exception \CouldNotSaveException (
84- __ ($ exception ->getMessage ()),
60+ throw new CouldNotSaveException (
61+ __ ('Could not save the Shipment Point ' ),
62+ $ exception ,
8563 );
8664 }
8765
8866 return $ entity ;
8967 }
9068
9169 /**
92- * @param \Mygento\Shipment\Api\Data\PointInterface $entity
93- * @throws \Magento\Framework\Exception\CouldNotDeleteException
94- * @return bool
70+ * @throws CouldNotDeleteException
9571 */
96- public function delete (\ Mygento \ Shipment \ Api \ Data \ PointInterface $ entity )
72+ public function delete (PointInterface $ entity ): bool
9773 {
9874 try {
9975 $ this ->resource ->delete ($ entity );
10076 } catch (\Exception $ exception ) {
101- throw new \ Magento \ Framework \ Exception \ CouldNotDeleteException (
77+ throw new CouldNotDeleteException (
10278 __ ($ exception ->getMessage ()),
10379 );
10480 }
@@ -107,30 +83,22 @@ public function delete(\Mygento\Shipment\Api\Data\PointInterface $entity)
10783 }
10884
10985 /**
110- * @param int $entityId
111- * @throws \Magento\Framework\Exception\NoSuchEntityException
112- * @throws \Magento\Framework\Exception\CouldNotDeleteException
113- * @return bool
86+ * @throws NoSuchEntityException
87+ * @throws CouldNotDeleteException
11488 */
115- public function deleteById ($ entityId )
89+ public function deleteById (int $ entityId ): bool
11690 {
11791 return $ this ->delete ($ this ->getById ($ entityId ));
11892 }
11993
120- /**
121- * @param \Magento\Framework\Api\SearchCriteriaInterface $criteria
122- * @return \Mygento\Shipment\Api\Data\PointSearchResultsInterface
123- */
124- public function getList (\Magento \Framework \Api \SearchCriteriaInterface $ criteria )
94+ public function getList (SearchCriteriaInterface $ criteria ): PointSearchResultsInterface
12595 {
12696 /** @var \Mygento\Shipment\Model\ResourceModel\Point\Collection $collection */
12797 $ collection = $ this ->collectionFactory ->create ();
12898
129- if ($ this ->collectionProcessor ) {
130- $ this ->collectionProcessor ->process ($ criteria , $ collection );
131- }
99+ $ this ->collectionProcessor ->process ($ criteria , $ collection );
132100
133- /** @var \Mygento\Shipment\Api\Data\ PointSearchResultsInterface $searchResults */
101+ /** @var PointSearchResultsInterface $searchResults */
134102 $ searchResults = $ this ->searchResultsFactory ->create ();
135103 $ searchResults ->setSearchCriteria ($ criteria );
136104 $ searchResults ->setItems ($ collection ->getItems ());
0 commit comments