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;
23use function trim;
24
25/**
26 * Generates unified diffs using the default Sebastian diff output builder.
27 */
28  class UnifiedDiffer implements DifferInterface
29{
30    /**
31     * Creates a new unified differ.
32     *
33     * @param Differ $differ the underlying Sebastian differ
34     */
35    public function __construct(
36        private Differ $differ
37    ) {}
38
39    /**
40     * Generates a unified diff between current and updated content.
41     *
42     * @param string $currentContent the current content
43     * @param string $updatedContent the updated content
44     *
45     * @return string the unified diff
46     */
47    public function diff(string $currentContent, string $updatedContent): string
48    {
49        return trim($this->differ->diff($currentContent, $updatedContent));
50    }
51}