1<?php
2
3/*
4 * This file is part of Twig.
5 *
6 * (c) Fabien Potencier
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12namespace Twig;
13
14/**
15 * @author Fabien Potencier <fabien@symfony.com>
16 */
17final class DeprecatedCallableInfo
18{
19    private string $type;
20    private string $name;
21
22    public function __construct(
23        private string $package,
24        private string $version,
25        private ?string $altName = null,
26        private ?string $altPackage = null,
27        private ?string $altVersion = null,
28    ) {
29    }
30
31    public function setType(string $type): void
32    {
33        $this->type = $type;
34    }
35
36    public function setName(string $name): void
37    {
38        $this->name = $name;
39    }
40
41    public function triggerDeprecation(?string $file = null, ?int $line = null): void
42    {
43        $message = \sprintf('Twig %s "%s" is deprecated', ucfirst($this->type), $this->name);
44
45        if ($this->altName) {
46            $message .= \sprintf('; use "%s"', $this->altName);
47            if ($this->altPackage) {
48                $message .= \sprintf(' from the "%s" package', $this->altPackage);
49            }
50            if ($this->altVersion) {
51                $message .= \sprintf(' (available since version %s)', $this->altVersion);
52            }
53            $message .= ' instead';
54        }
55
56        if ($file) {
57            $message .= \sprintf(' in %s', $file);
58            if ($line) {
59                $message .= \sprintf(' at line %d', $line);
60            }
61        }
62
63        $message .= '.';
64
65        trigger_deprecation($this->package, $this->version, $message);
66    }
67}
68