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 | ||
| 25 | class SentryAdaptor | ||
| 26 | { | ||
| 27 | use Configurable; | ||
| 28 | |||
| 29 | /** | ||
| 30 | * @var ClientInterface | ||
| 31 | */ | ||
| 32 | protected $sentry; | ||
| 33 | |||
| 34 | /** | ||
| 35 | * Internal storage for context. Used only in the case of non-exception | ||
| 36 | * data sent to Sentry. | ||
| 37 | * | ||
| 38 | * @var array | ||
| 39 | */ | ||
| 40 | protected $context = []; | ||
| 41 | |||
| 42 | /** | ||
| 43 | * @return void | ||
|  | |||
| 44 | */ | ||
| 45 | public function __construct() | ||
| 52 | |||
| 53 | /** | ||
| 54 | * @return ClientInterface | ||
| 55 | */ | ||
| 56 | public function getSDK() : ClientInterface | ||
| 60 | |||
| 61 | /** | ||
| 62 | * Configures Sentry "context" to display additional information about a SilverStripe | ||
| 63 | * application's runtime and context. | ||
| 64 | * | ||
| 65 | * @param string $field | ||
| 66 | * @param mixed $data | ||
| 67 | * @return void | ||
| 68 | * @throws SentryLogWriterException | ||
| 69 | */ | ||
| 70 | public function setContext(string $field, $data) : void | ||
| 111 | |||
| 112 | /** | ||
| 113 | * Get _locally_ set contextual data, that we should be able to get from Sentry's | ||
| 114 |      * current {@link Scope}. | ||
| 115 | * | ||
| 116 |      * Note: This (re) sets data to a new instance of {@link Scope} for passing to  | ||
| 117 | * captureMessage(). One would expect this to be set by default, as it is for | ||
| 118 | * $record data sent to Sentry via captureException(), but it isn't. | ||
| 119 | * | ||
| 120 | * @todo Investigate sentry/php-sdk's API for alternative ways to handle "manual" | ||
| 121 | * logging, where data is not an exception and results in being passed to captureMessage(). | ||
| 122 | * | ||
| 123 | * @return Scope | ||
| 124 | */ | ||
| 125 | public function getContext() : Scope | ||
| 141 | |||
| 142 | /** | ||
| 143 | * Get various userland options to pass to Raven. Includes detecting and setting | ||
| 144 | * proxy options too. | ||
| 145 | * | ||
| 146 | * @param string $opt | ||
| 147 | * @return mixed string|array|null depending on whether $opts is passed. | ||
| 148 | */ | ||
| 149 | protected function getOpts(string $opt = '') | ||
| 176 | } | ||
| 177 | 
Adding a
@returnannotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.