| Conditions | 5 |
| Paths | 8 |
| Total Lines | 55 |
| Code Lines | 32 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 60 | public function __construct( |
||
| 61 | Config $config, |
||
| 62 | ?RepositoryInterface $repository = null, |
||
| 63 | ?CacheInterface $cache = null, |
||
| 64 | ?EventDispatcherInterface $eventDispatcher = null, |
||
| 65 | ?SocketInterface $socket = null, |
||
| 66 | ?LoggerInterface $logger = null |
||
| 67 | ) { |
||
| 68 | $this->config = $config; |
||
| 69 | $this->logger = $logger ?? new NullLogger(); |
||
| 70 | $config->validate(); |
||
| 71 | |||
| 72 | if (null === $repository) { |
||
| 73 | $this->connection = DriverManager::getConnection( |
||
| 74 | [ |
||
| 75 | 'user' => $config->getUser(), |
||
| 76 | 'password' => $config->getPassword(), |
||
| 77 | 'host' => $config->getHost(), |
||
| 78 | 'port' => $config->getPort(), |
||
| 79 | 'driver' => 'pdo_mysql', |
||
| 80 | 'charset' => $config->getCharset() |
||
| 81 | ] |
||
| 82 | ); |
||
| 83 | $repository = new MySQLRepository($this->connection); |
||
| 84 | } |
||
| 85 | if (null === $cache) { |
||
| 86 | $cache = new ArrayCache($config->getTableCacheSize()); |
||
| 87 | } |
||
| 88 | |||
| 89 | $this->eventDispatcher = $eventDispatcher ?: new EventDispatcher(); |
||
| 90 | |||
| 91 | if (null === $socket) { |
||
| 92 | $socket = new Socket(); |
||
| 93 | } |
||
| 94 | |||
| 95 | $this->binLogServerConnect = new BinLogSocketConnect( |
||
| 96 | $config, |
||
| 97 | $repository, |
||
| 98 | $socket |
||
| 99 | ); |
||
| 100 | |||
| 101 | $this->event = new Event( |
||
| 102 | $config, |
||
| 103 | $this->binLogServerConnect, |
||
| 104 | new RowEventFactory( |
||
| 105 | $config, |
||
| 106 | $repository, |
||
| 107 | $cache |
||
| 108 | ), |
||
| 109 | $this->eventDispatcher, |
||
| 110 | $cache |
||
| 111 | ); |
||
| 112 | |||
| 113 | $this->socket = $socket; |
||
| 114 | $this->connect(); |
||
| 115 | } |
||
| 201 |