Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
UnifiedDiffer
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
2 / 2
2
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 diff
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5/**
6 * Fast Forward Development Tools for PHP projects.
7 *
8 * This file is part of fast-forward/dev-tools project.
9 *
10 * @author   Felipe SayĆ£o Lobato Abreu <github@mentordosnerds.com>
11 * @license  https://opensource.org/licenses/MIT MIT License
12 *
13 * @see      https://github.com/php-fast-forward/
14 * @see      https://github.com/php-fast-forward/dev-tools
15 * @see      https://github.com/php-fast-forward/dev-tools/issues
16 * @see      https://php-fast-forward.github.io/dev-tools/
17 * @see      https://datatracker.ietf.org/doc/html/rfc2119
18 */
19
20namespace FastForward\DevTools\Resource;
21
22use SebastianBergmann\Diff\Differ;
23
24use function trim;
25
26/**
27 * Generates unified diffs using the default Sebastian diff output builder.
28 */
29  class UnifiedDiffer implements DifferInterface
30{
31    /**
32     * Creates a new unified differ.
33     *
34     * @param Differ $differ the underlying Sebastian differ
35     */
36    public function __construct(
37        private Differ $differ
38    ) {}
39
40    /**
41     * Generates a unified diff between current and updated content.
42     *
43     * @param string $currentContent the current content
44     * @param string $updatedContent the updated content
45     *
46     * @return string the unified diff
47     */
48    public function diff(string $currentContent, string $updatedContent): string
49    {
50        return trim($this->differ->diff($currentContent, $updatedContent));
51    }
52}