1010use Magento \CloudPatches \Composer \MagentoVersion ;
1111use Magento \CloudPatches \Filesystem \Filesystem ;
1212use Magento \CloudPatches \Patch \Status \StatusPool ;
13- use Magento \CloudPatches \Shell \ProcessFactory ;
14- use Symfony \Component \Process \Exception \ProcessFailedException ;
1513
1614/**
1715 * Applies and reverts patches.
1816 */
1917class Applier
2018{
2119 /**
22- * @var ProcessFactory
20+ * @var PatchCommandInterface
2321 */
24- private $ processFactory ;
22+ private $ patchCommand ;
2523
2624 /**
2725 * @var GitConverter
@@ -39,18 +37,18 @@ class Applier
3937 private $ filesystem ;
4038
4139 /**
42- * @param ProcessFactory $processFactory
40+ * @param PatchCommandInterface $patchCommand
4341 * @param GitConverter $gitConverter
4442 * @param MagentoVersion $magentoVersion
4543 * @param Filesystem $filesystem
4644 */
4745 public function __construct (
48- ProcessFactory $ processFactory ,
46+ PatchCommandInterface $ patchCommand ,
4947 GitConverter $ gitConverter ,
5048 MagentoVersion $ magentoVersion ,
5149 Filesystem $ filesystem
5250 ) {
53- $ this ->processFactory = $ processFactory ;
51+ $ this ->patchCommand = $ patchCommand ;
5452 $ this ->gitConverter = $ gitConverter ;
5553 $ this ->magentoVersion = $ magentoVersion ;
5654 $ this ->filesystem = $ filesystem ;
@@ -69,13 +67,11 @@ public function apply(string $path, string $id): string
6967 {
7068 $ content = $ this ->readContent ($ path );
7169 try {
72- $ this ->processFactory ->create (['git ' , 'apply ' ], $ content )
73- ->mustRun ();
74- } catch (ProcessFailedException $ exception ) {
70+ $ this ->patchCommand ->apply ($ content );
71+ } catch (PatchCommandException $ exception ) {
7572 try {
76- $ this ->processFactory ->create (['git ' , 'apply ' , '--check ' , '--reverse ' ], $ content )
77- ->mustRun ();
78- } catch (ProcessFailedException $ reverseException ) {
73+ $ this ->patchCommand ->revertCheck ($ content );
74+ } catch (PatchCommandException $ reverseException ) {
7975 throw new ApplierException ($ exception ->getMessage (), $ exception ->getCode ());
8076 }
8177
@@ -98,13 +94,11 @@ public function revert(string $path, string $id): string
9894 {
9995 $ content = $ this ->readContent ($ path );
10096 try {
101- $ this ->processFactory ->create (['git ' , 'apply ' , '--reverse ' ], $ content )
102- ->mustRun ();
103- } catch (ProcessFailedException $ exception ) {
97+ $ this ->patchCommand ->revert ($ content );
98+ } catch (PatchCommandException $ exception ) {
10499 try {
105- $ this ->processFactory ->create (['git ' , 'apply ' , '--check ' ], $ content )
106- ->mustRun ();
107- } catch (ProcessFailedException $ applyException ) {
100+ $ this ->patchCommand ->applyCheck ($ content );
101+ } catch (PatchCommandException $ applyException ) {
108102 throw new ApplierException ($ exception ->getMessage (), $ exception ->getCode ());
109103 }
110104
@@ -124,13 +118,11 @@ public function status(string $patchContent): string
124118 {
125119 $ patchContent = $ this ->prepareContent ($ patchContent );
126120 try {
127- $ this ->processFactory ->create (['git ' , 'apply ' , '--check ' ], $ patchContent )
128- ->mustRun ();
129- } catch (ProcessFailedException $ exception ) {
121+ $ this ->patchCommand ->applyCheck ($ patchContent );
122+ } catch (PatchCommandException $ exception ) {
130123 try {
131- $ this ->processFactory ->create (['git ' , 'apply ' , '--check ' , '--reverse ' ], $ patchContent )
132- ->mustRun ();
133- } catch (ProcessFailedException $ reverseException ) {
124+ $ this ->patchCommand ->revertCheck ($ patchContent );
125+ } catch (PatchCommandException $ reverseException ) {
134126 return StatusPool::NA ;
135127 }
136128
@@ -150,9 +142,8 @@ public function checkApply(string $patchContent): bool
150142 {
151143 $ patchContent = $ this ->prepareContent ($ patchContent );
152144 try {
153- $ this ->processFactory ->create (['git ' , 'apply ' , '--check ' ], $ patchContent )
154- ->mustRun ();
155- } catch (ProcessFailedException $ exception ) {
145+ $ this ->patchCommand ->applyCheck ($ patchContent );
146+ } catch (PatchCommandException $ exception ) {
156147 return false ;
157148 }
158149
0 commit comments