| Conditions | 3 |
| Paths | 6 |
| Total Lines | 33 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 19 |
| CRAP Score | 3 |
| Changes | 0 | ||
| 1 | <?php declare(strict_types=1); |
||
| 37 | 10 | public function replace( |
|
| 38 | ColumnMetadata $columnMetadata, |
||
| 39 | string $searchTerm, |
||
| 40 | string $replaceTerm, |
||
| 41 | string $subject |
||
| 42 | ): FieldReplaceResult { |
||
| 43 | 10 | $editor = new Editor(); |
|
| 44 | |||
| 45 | try { |
||
| 46 | 10 | $matchCount = $editor->containsCount($subject, $searchTerm); |
|
| 47 | 9 | $errorList = []; |
|
| 48 | |||
| 49 | 9 | if (0 === $matchCount) { |
|
| 50 | 3 | $errorList[] = 'Search term "' . $searchTerm . '" not found in subject "' . $subject . '"'; |
|
| 51 | } |
||
| 52 | |||
| 53 | 9 | return new FieldReplaceResult( |
|
| 54 | 9 | $columnMetadata, |
|
| 55 | 9 | $matchCount, |
|
| 56 | 9 | $errorList, |
|
| 57 | 9 | $subject, |
|
| 58 | 9 | $editor->replace($subject, $searchTerm, $replaceTerm) |
|
| 59 | ); |
||
| 60 | 1 | } catch (\Throwable $e) { |
|
| 61 | 1 | return new FieldReplaceResult( |
|
| 62 | 1 | $columnMetadata, |
|
| 63 | 1 | 0, |
|
| 64 | 1 | ['Failed to deserialize field'], |
|
| 65 | 1 | $subject, |
|
| 66 | 1 | $subject |
|
| 67 | ); |
||
| 68 | } |
||
| 69 | } |
||
| 70 | } |