File tree Expand file tree Collapse file tree 2 files changed +27
-1
lines changed Expand file tree Collapse file tree 2 files changed +27
-1
lines changed Original file line number Diff line number Diff line change @@ -240,7 +240,10 @@ public function getWorkDir(): string
240240 */
241241 public function setWorkDir (string $ workDir ): static
242242 {
243- Assert::isDir ($ workDir , "workdir is not exists. path: $ workDir " );
243+ if ($ workDir ) {
244+ Assert::isDir ($ workDir , "workdir is not exists. path: $ workDir " );
245+ }
246+
244247 $ this ->workDir = $ workDir ;
245248 return $ this ;
246249 }
Original file line number Diff line number Diff line change @@ -131,6 +131,29 @@ public function addArgs(...$args): static
131131 return $ this ;
132132 }
133133
134+ /**
135+ * Call fn on args is not empty.
136+ *
137+ * Usage:
138+ *
139+ * ```php
140+ * $c->withIf(fn($args) => $c->addArgs(...$args), $args)
141+ * ```
142+ *
143+ * @template T
144+ * @param callable(T): void $fn
145+ * @param T $args
146+ *
147+ * @return $this
148+ */
149+ public function withIf (callable $ fn , mixed $ args ): static
150+ {
151+ if ($ args ) {
152+ $ fn ($ this );
153+ }
154+ return $ this ;
155+ }
156+
134157 /**
135158 * @param bool $printOutput
136159 *
You can’t perform that action at this time.
0 commit comments