Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
1 | <?php |
||
38 | class ProcessSamlAuthenticationHandler implements AuthenticationHandler |
||
39 | { |
||
40 | /** |
||
41 | * @var AuthenticationHandler |
||
42 | */ |
||
43 | private $nextHandler; |
||
44 | |||
45 | /** |
||
46 | * @var TokenStorageInterface |
||
47 | */ |
||
48 | private $tokenStorage; |
||
49 | |||
50 | /** |
||
51 | * @var SamlInteractionProvider |
||
52 | */ |
||
53 | private $samlInteractionProvider; |
||
54 | |||
55 | /** |
||
56 | * @var SamlAuthenticationStateHandler |
||
57 | */ |
||
58 | private $authenticationStateHandler; |
||
59 | |||
60 | /** |
||
61 | * @var AuthenticatedSessionStateHandler |
||
62 | */ |
||
63 | private $authenticatedSession; |
||
64 | |||
65 | /** |
||
66 | * @var AuthenticationManagerInterface |
||
67 | */ |
||
68 | private $authenticationManager; |
||
69 | |||
70 | /** |
||
71 | * @var SamlAuthenticationLogger |
||
72 | */ |
||
73 | private $authenticationLogger; |
||
74 | |||
75 | /** |
||
76 | * @var EngineInterface |
||
77 | */ |
||
78 | private $templating; |
||
79 | |||
80 | View Code Duplication | public function __construct( |
|
|
|||
81 | TokenStorageInterface $tokenStorage, |
||
82 | SamlInteractionProvider $samlInteractionProvider, |
||
83 | SamlAuthenticationStateHandler $authenticationStateHandler, |
||
84 | AuthenticatedSessionStateHandler $authenticatedSession, |
||
85 | AuthenticationManagerInterface $authenticationManager, |
||
86 | SamlAuthenticationLogger $authenticationLogger, |
||
87 | EngineInterface $templating |
||
88 | ) { |
||
89 | $this->tokenStorage = $tokenStorage; |
||
90 | $this->samlInteractionProvider = $samlInteractionProvider; |
||
91 | $this->authenticationStateHandler = $authenticationStateHandler; |
||
92 | $this->authenticatedSession = $authenticatedSession; |
||
93 | $this->authenticationManager = $authenticationManager; |
||
94 | $this->authenticationLogger = $authenticationLogger; |
||
95 | $this->templating = $templating; |
||
96 | } |
||
97 | |||
98 | public function process(GetResponseEvent $event) |
||
138 | |||
139 | public function setNext(AuthenticationHandler $handler) |
||
143 | } |
||
144 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.