Complex classes like FunFunFactory often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use FunFunFactory, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 153 | class FunFunFactory { |
||
| 154 | |||
| 155 | private $config; |
||
| 156 | |||
| 157 | /** |
||
| 158 | * @var \Pimple |
||
| 159 | */ |
||
| 160 | private $pimple; |
||
| 161 | |||
| 162 | private $addDoctrineSubscribers = true; |
||
| 163 | |||
| 164 | /** |
||
| 165 | * @var Stopwatch|null |
||
| 166 | */ |
||
| 167 | private $profiler = null; |
||
| 168 | |||
| 169 | 137 | public function __construct( array $config ) { |
|
| 170 | 137 | $this->config = $config; |
|
| 171 | 137 | $this->pimple = $this->newPimple(); |
|
| 172 | 137 | } |
|
| 173 | |||
| 174 | 137 | private function newPimple(): \Pimple { |
|
| 175 | 137 | $pimple = new \Pimple(); |
|
| 176 | |||
| 177 | $pimple['logger'] = $pimple->share( function() { |
||
| 178 | 100 | return new NullLogger(); |
|
| 179 | 137 | } ); |
|
| 180 | |||
| 181 | $pimple['profiler_data_collector'] = $pimple->share( function() { |
||
| 182 | return new ProfilerDataCollector(); |
||
| 183 | 137 | } ); |
|
| 184 | |||
| 185 | $pimple['dbal_connection'] = $pimple->share( function() { |
||
| 186 | 137 | return DriverManager::getConnection( $this->config['db'] ); |
|
| 187 | 137 | } ); |
|
| 188 | |||
| 189 | $pimple['entity_manager'] = $pimple->share( function() { |
||
| 190 | 74 | $entityManager = ( new StoreFactory( $this->getConnection() ) )->getEntityManager(); |
|
| 191 | 74 | if ( $this->addDoctrineSubscribers ) { |
|
| 192 | 74 | $entityManager->getEventManager()->addEventSubscriber( $this->newDoctrineDonationPrePersistSubscriber() ); |
|
| 193 | 74 | $entityManager->getEventManager()->addEventSubscriber( $this->newDoctrineMembershipApplicationPrePersistSubscriber() ); |
|
| 194 | } |
||
| 195 | |||
| 196 | 74 | return $entityManager; |
|
| 197 | 137 | } ); |
|
| 198 | |||
| 199 | $pimple['subscription_repository'] = $pimple->share( function() { |
||
| 200 | 8 | return new LoggingSubscriptionRepository( |
|
| 201 | 8 | new DoctrineSubscriptionRepository( $this->getEntityManager() ), |
|
| 202 | 8 | $this->getLogger() |
|
| 203 | ); |
||
| 204 | 137 | } ); |
|
| 205 | |||
| 206 | $pimple['donation_repository'] = $pimple->share( function() { |
||
| 207 | 36 | return new LoggingDonationRepository( |
|
| 208 | 36 | new DoctrineDonationRepository( $this->getEntityManager() ), |
|
| 209 | 36 | $this->getLogger() |
|
| 210 | ); |
||
| 211 | 137 | } ); |
|
| 212 | |||
| 213 | $pimple['membership_application_repository'] = $pimple->share( function() { |
||
| 214 | 10 | return new LoggingApplicationRepository( |
|
| 215 | 10 | new DoctrineApplicationRepository( $this->getEntityManager() ), |
|
| 216 | 10 | $this->getLogger() |
|
| 217 | ); |
||
| 218 | 137 | } ); |
|
| 219 | |||
| 220 | $pimple['comment_repository'] = $pimple->share( function() { |
||
| 221 | 12 | $finder = new LoggingCommentFinder( |
|
| 222 | 12 | new DoctrineCommentFinder( $this->getEntityManager() ), |
|
| 223 | 12 | $this->getLogger() |
|
| 224 | ); |
||
| 225 | |||
| 226 | 12 | return $this->addProfilingDecorator( $finder, 'CommentFinder' ); |
|
| 227 | 137 | } ); |
|
| 228 | |||
| 229 | $pimple['mail_validator'] = $pimple->share( function() { |
||
| 230 | 37 | return new EmailValidator( new InternetDomainNameValidator() ); |
|
| 231 | 137 | } ); |
|
| 232 | |||
| 233 | $pimple['subscription_validator'] = $pimple->share( function() { |
||
| 234 | 6 | return new SubscriptionValidator( |
|
| 235 | 6 | $this->getEmailValidator(), |
|
| 236 | 6 | $this->newTextPolicyValidator( 'fields' ), |
|
| 237 | 6 | $this->newSubscriptionDuplicateValidator(), |
|
| 238 | 6 | $this->newHonorificValidator() |
|
| 239 | ); |
||
| 240 | 137 | } ); |
|
| 241 | |||
| 242 | $pimple['template_name_validator'] = $pimple->share( function() { |
||
| 243 | 8 | return new TemplateNameValidator( $this->getTwig() ); |
|
| 244 | 137 | } ); |
|
| 245 | |||
| 246 | $pimple['contact_validator'] = $pimple->share( function() { |
||
| 247 | 3 | return new GetInTouchValidator( $this->getEmailValidator() ); |
|
| 248 | 137 | } ); |
|
| 249 | |||
| 250 | $pimple['greeting_generator'] = $pimple->share( function() { |
||
| 251 | 42 | return new GreetingGenerator(); |
|
| 252 | 137 | } ); |
|
| 253 | |||
| 254 | $pimple['mw_api'] = $pimple->share( function() { |
||
| 255 | 81 | return new MediawikiApi( |
|
| 256 | 81 | $this->config['cms-wiki-api-url'], |
|
| 257 | 81 | $this->getGuzzleClient() |
|
| 258 | ); |
||
| 259 | 137 | } ); |
|
| 260 | |||
| 261 | $pimple['guzzle_client'] = $pimple->share( function() { |
||
| 262 | 81 | $middlewareFactory = new MiddlewareFactory(); |
|
| 263 | 81 | $middlewareFactory->setLogger( $this->getLogger() ); |
|
| 264 | |||
| 265 | 81 | $handlerStack = HandlerStack::create( new CurlHandler() ); |
|
| 266 | 81 | $handlerStack->push( $middlewareFactory->retry() ); |
|
| 267 | |||
| 268 | 81 | $guzzle = new Client( [ |
|
| 269 | 81 | 'cookies' => true, |
|
| 270 | 81 | 'handler' => $handlerStack, |
|
| 271 | 'headers' => [ 'User-Agent' => 'WMDE Fundraising Frontend' ], |
||
| 272 | ] ); |
||
| 273 | |||
| 274 | 81 | return $this->addProfilingDecorator( $guzzle, 'Guzzle Client' ); |
|
| 275 | 137 | } ); |
|
| 276 | |||
| 277 | $pimple['translator'] = $pimple->share( function() { |
||
| 278 | 93 | $translationFactory = new TranslationFactory(); |
|
| 279 | $loaders = [ |
||
| 280 | 93 | 'json' => $translationFactory->newJsonLoader() |
|
| 281 | ]; |
||
| 282 | 93 | $locale = $this->config['locale']; |
|
| 283 | 93 | $translator = $translationFactory->create( $loaders, $locale ); |
|
| 284 | 93 | $translator->addResource( |
|
| 285 | 93 | 'json', |
|
| 286 | 93 | __DIR__ . '/../../app/translations/messages.' . $locale . '.json', |
|
| 287 | $locale |
||
| 288 | ); |
||
| 289 | |||
| 290 | 93 | $translator->addResource( |
|
| 291 | 93 | 'json', |
|
| 292 | 93 | __DIR__ . '/../../app/translations/paymentTypes.' . $locale . '.json', |
|
| 293 | $locale, |
||
| 294 | 93 | 'paymentTypes' |
|
| 295 | ); |
||
| 296 | |||
| 297 | 93 | $translator->addResource( |
|
| 298 | 93 | 'json', |
|
| 299 | 93 | __DIR__ . '/../../app/translations/paymentIntervals.' . $locale . '.json', |
|
| 300 | $locale, |
||
| 301 | 93 | 'paymentIntervals' |
|
| 302 | ); |
||
| 303 | |||
| 304 | 93 | $translator->addResource( |
|
| 305 | 93 | 'json', |
|
| 306 | 93 | __DIR__ . '/../../app/translations/donationStatus.' . $locale . '.json', |
|
| 307 | $locale, |
||
| 308 | 93 | 'donationStatus' |
|
| 309 | ); |
||
| 310 | |||
| 311 | 93 | $translator->addResource( |
|
| 312 | 93 | 'json', |
|
| 313 | 93 | __DIR__ . '/../../app/translations/validations.' . $locale . '.json', |
|
| 314 | $locale, |
||
| 315 | 93 | 'validations' |
|
| 316 | ); |
||
| 317 | |||
| 318 | 93 | return $translator; |
|
| 319 | 137 | } ); |
|
| 320 | |||
| 321 | // In the future, this could be locale-specific or filled from a DB table |
||
| 322 | $pimple['honorifics'] = $pimple->share( function() { |
||
| 323 | 67 | return new Honorifics( [ |
|
| 324 | 67 | '' => 'Kein Titel', |
|
| 325 | 'Dr.' => 'Dr.', |
||
| 326 | 'Prof.' => 'Prof.', |
||
| 327 | 'Prof. Dr.' => 'Prof. Dr.' |
||
| 328 | ] ); |
||
| 329 | 137 | } ); |
|
| 330 | |||
| 331 | $pimple['twig_factory'] = $pimple->share( function () { |
||
| 332 | // TODO: like this we end up with two Twig instance, one created here and on in the framework |
||
| 333 | 88 | return new TwigFactory( $this->config['twig'], $this->getCachePath() . '/twig' ); |
|
| 334 | 137 | } ); |
|
| 335 | |||
| 336 | $pimple['twig'] = $pimple->share( function() { |
||
| 337 | 88 | $twigFactory = $this->getTwigFactory(); |
|
| 338 | 88 | $loaders = array_filter( [ |
|
| 339 | 88 | $twigFactory->newFileSystemLoader(), |
|
| 340 | 88 | $twigFactory->newArrayLoader(), // This is just a fallback for testing |
|
| 341 | 88 | $twigFactory->newWikiPageLoader( $this->newWikiPageRetriever() ), |
|
| 342 | ] ); |
||
| 343 | $extensions = [ |
||
| 344 | 88 | $twigFactory->newTranslationExtension( $this->getTranslator() ), |
|
| 345 | 88 | new Twig_Extensions_Extension_Intl() |
|
| 346 | ]; |
||
| 347 | $filters = [ |
||
| 348 | 88 | $twigFactory->newFilePrefixFilter( |
|
| 349 | 88 | $this->newFilePrefixer() |
|
| 350 | ) |
||
| 351 | ]; |
||
| 352 | |||
| 353 | 88 | return $twigFactory->create( $loaders, $extensions, $filters ); |
|
| 354 | 137 | } ); |
|
| 355 | |||
| 356 | $pimple['messenger'] = $pimple->share( function() { |
||
| 357 | 5 | return new Messenger( |
|
| 358 | 5 | new Swift_MailTransport(), |
|
| 359 | 5 | $this->getOperatorAddress(), |
|
| 360 | 5 | $this->config['operator-displayname'] |
|
| 361 | ); |
||
| 362 | 137 | } ); |
|
| 363 | |||
| 364 | $pimple['confirmation-page-selector'] = $pimple->share( function() { |
||
| 365 | 14 | return new DonationConfirmationPageSelector( $this->config['confirmation-pages'] ); |
|
| 366 | 137 | } ); |
|
| 367 | |||
| 368 | $pimple['paypal-payment-notification-verifier'] = $pimple->share( function() { |
||
| 369 | return new LoggingPaymentNotificationVerifier( |
||
| 370 | new PayPalPaymentNotificationVerifier( |
||
| 371 | new Client(), |
||
| 372 | $this->config['paypal'] |
||
| 373 | ), |
||
| 374 | $this->getLogger() |
||
| 375 | ); |
||
| 376 | 137 | } ); |
|
| 377 | |||
| 378 | $pimple['credit-card-api-service'] = $pimple->share( function() { |
||
| 379 | return new McpCreditCardService( |
||
| 380 | new TNvpServiceDispatcher( |
||
| 381 | 'IMcpCreditcardService_v1_5', |
||
| 382 | 'https://sipg.micropayment.de/public/creditcard/v1.5/nvp/' |
||
| 383 | ), |
||
| 384 | $this->config['creditcard']['access-key'], |
||
| 385 | $this->config['creditcard']['testmode'] |
||
| 386 | ); |
||
| 387 | 137 | } ); |
|
| 388 | |||
| 389 | $pimple['token_generator'] = $pimple->share( function() { |
||
| 390 | 57 | return new RandomTokenGenerator( |
|
| 391 | 57 | $this->config['token-length'], |
|
| 392 | 57 | new \DateInterval( $this->config['token-validity-timestamp'] ) |
|
| 393 | ); |
||
| 394 | 137 | } ); |
|
| 395 | |||
| 396 | $pimple['page_cache'] = $pimple->share( function() { |
||
| 397 | 91 | return new VoidCache(); |
|
| 398 | 137 | } ); |
|
| 399 | |||
| 400 | 137 | return $pimple; |
|
| 401 | } |
||
| 402 | |||
| 403 | 137 | public function getConnection(): Connection { |
|
| 404 | 137 | return $this->pimple['dbal_connection']; |
|
| 405 | } |
||
| 406 | |||
| 407 | 74 | public function getEntityManager(): EntityManager { |
|
| 408 | 74 | return $this->pimple['entity_manager']; |
|
| 409 | } |
||
| 410 | |||
| 411 | 8 | private function newDonationEventLogger(): DonationEventLogger { |
|
| 412 | 8 | return new BestEffortDonationEventLogger( |
|
| 413 | 8 | new DoctrineDonationEventLogger( $this->getEntityManager() ), |
|
| 414 | 8 | $this->getLogger() |
|
| 415 | ); |
||
| 416 | } |
||
| 417 | |||
| 418 | 137 | public function newInstaller(): Installer { |
|
| 419 | 137 | return ( new StoreFactory( $this->getConnection() ) )->newInstaller(); |
|
| 420 | } |
||
| 421 | |||
| 422 | 12 | public function newListCommentsUseCase(): ListCommentsUseCase { |
|
| 423 | 12 | return new ListCommentsUseCase( $this->getCommentFinder() ); |
|
| 424 | } |
||
| 425 | |||
| 426 | 6 | public function newCommentListJsonPresenter(): CommentListJsonPresenter { |
|
| 427 | 6 | return new CommentListJsonPresenter(); |
|
| 428 | } |
||
| 429 | |||
| 430 | 2 | public function newCommentListRssPresenter(): CommentListRssPresenter { |
|
| 431 | 2 | return new CommentListRssPresenter( new TwigTemplate( |
|
| 432 | 2 | $this->getTwig(), |
|
| 433 | 2 | 'CommentList.rss.twig' |
|
| 434 | ) ); |
||
| 435 | } |
||
| 436 | |||
| 437 | 4 | public function newCommentListHtmlPresenter(): CommentListHtmlPresenter { |
|
| 438 | 4 | return new CommentListHtmlPresenter( $this->getLayoutTemplate( 'CommentList.html.twig', [ 'piwikGoals' => [ 1 ] ] ) ); |
|
| 439 | } |
||
| 440 | |||
| 441 | 12 | private function getCommentFinder(): CommentFinder { |
|
| 442 | 12 | return $this->pimple['comment_repository']; |
|
| 443 | } |
||
| 444 | |||
| 445 | 9 | public function getSubscriptionRepository(): SubscriptionRepository { |
|
| 446 | 9 | return $this->pimple['subscription_repository']; |
|
| 447 | } |
||
| 448 | |||
| 449 | 1 | public function setSubscriptionRepository( SubscriptionRepository $subscriptionRepository ) { |
|
| 450 | 1 | $this->pimple['subscription_repository'] = $subscriptionRepository; |
|
| 451 | 1 | } |
|
| 452 | |||
| 453 | 6 | private function getSubscriptionValidator(): SubscriptionValidator { |
|
| 454 | 6 | return $this->pimple['subscription_validator']; |
|
| 455 | } |
||
| 456 | |||
| 457 | 37 | public function getEmailValidator(): EmailValidator { |
|
| 458 | 37 | return $this->pimple['mail_validator']; |
|
| 459 | } |
||
| 460 | |||
| 461 | 8 | public function getTemplateNameValidator(): TemplateNameValidator { |
|
| 462 | 8 | return $this->pimple['template_name_validator']; |
|
| 463 | } |
||
| 464 | |||
| 465 | 1 | public function newAddSubscriptionHTMLPresenter(): AddSubscriptionHtmlPresenter { |
|
| 466 | 1 | return new AddSubscriptionHtmlPresenter( $this->getIncludeTemplate( 'Subscription_Form.twig' ), $this->getTranslator() ); |
|
| 467 | } |
||
| 468 | |||
| 469 | 3 | public function newConfirmSubscriptionHtmlPresenter(): ConfirmSubscriptionHtmlPresenter { |
|
| 470 | 3 | return new ConfirmSubscriptionHtmlPresenter( |
|
| 471 | 3 | $this->getLayoutTemplate( 'ConfirmSubscription.html.twig' ), |
|
| 472 | 3 | $this->getTranslator() |
|
| 473 | ); |
||
| 474 | } |
||
| 475 | |||
| 476 | 2 | public function newAddSubscriptionJSONPresenter(): AddSubscriptionJsonPresenter { |
|
| 477 | 2 | return new AddSubscriptionJsonPresenter( $this->getTranslator() ); |
|
| 478 | } |
||
| 479 | |||
| 480 | 1 | public function newGetInTouchHTMLPresenter(): GetInTouchHtmlPresenter { |
|
| 481 | 1 | return new GetInTouchHtmlPresenter( $this->getIncludeTemplate( 'Kontaktformular.twig' ), $this->getTranslator() ); |
|
| 482 | } |
||
| 483 | |||
| 484 | 88 | public function getTwig(): Twig_Environment { |
|
| 485 | 88 | return $this->pimple['twig']; |
|
| 486 | } |
||
| 487 | |||
| 488 | /** |
||
| 489 | * Get a template, with the content for the layout areas filled in. |
||
| 490 | * |
||
| 491 | * @param string $templateName |
||
| 492 | * @param array $context Additional variables for the template |
||
| 493 | * @return TwigTemplate |
||
| 494 | */ |
||
| 495 | 31 | public function getLayoutTemplate( string $templateName, array $context = [] ): TwigTemplate { |
|
| 496 | 31 | return new TwigTemplate( |
|
| 497 | 31 | $this->getTwig(), |
|
| 498 | $templateName, |
||
| 499 | 31 | array_merge( $this->getDefaultTwigVariables(), $context ) |
|
| 500 | ); |
||
| 501 | } |
||
| 502 | |||
| 503 | /** |
||
| 504 | * Get a layouted template that includes another template |
||
| 505 | * |
||
| 506 | * @param string $templateName Template to include |
||
| 507 | * @return TwigTemplate |
||
| 508 | */ |
||
| 509 | 32 | private function getIncludeTemplate( string $templateName, array $context = [] ): TwigTemplate { |
|
| 510 | 32 | return new TwigTemplate( |
|
| 511 | 32 | $this->getTwig(), |
|
| 512 | 32 | 'IncludeInLayout.twig', |
|
| 513 | array_merge( |
||
| 514 | 32 | $this->getDefaultTwigVariables(), |
|
| 515 | 32 | [ 'main_template' => $templateName ], |
|
| 516 | $context |
||
| 517 | ) |
||
| 518 | ); |
||
| 519 | } |
||
| 520 | |||
| 521 | 62 | private function getDefaultTwigVariables() { |
|
| 522 | return [ |
||
| 523 | 62 | 'basepath' => $this->config['web-basepath'], |
|
| 524 | 62 | 'honorifics' => $this->getHonorifics()->getList(), |
|
| 525 | 62 | 'header_template' => $this->config['default-layout-templates']['header'], |
|
| 526 | 62 | 'footer_template' => $this->config['default-layout-templates']['footer'], |
|
| 527 | 62 | 'no_js_notice_template' => $this->config['default-layout-templates']['no-js-notice'], |
|
| 528 | 62 | 'piwik' => $this->config['piwik'], |
|
| 529 | ]; |
||
| 530 | } |
||
| 531 | |||
| 532 | 15 | private function newReferrerGeneralizer() { |
|
| 533 | 15 | return new ReferrerGeneralizer( |
|
| 534 | 15 | $this->config['referrer-generalization']['default'], |
|
| 535 | 15 | $this->config['referrer-generalization']['domain-map'] |
|
| 536 | ); |
||
| 537 | } |
||
| 538 | |||
| 539 | 91 | private function getMediaWikiApi(): MediawikiApi { |
|
| 540 | 91 | return $this->pimple['mw_api']; |
|
| 541 | } |
||
| 542 | |||
| 543 | 10 | public function setMediaWikiApi( MediawikiApi $api ) { |
|
| 544 | 10 | $this->pimple['mw_api'] = $api; |
|
| 545 | 10 | } |
|
| 546 | |||
| 547 | 81 | private function getGuzzleClient(): ClientInterface { |
|
| 548 | 81 | return $this->pimple['guzzle_client']; |
|
| 549 | } |
||
| 550 | |||
| 551 | 91 | private function newWikiPageRetriever(): PageRetriever { |
|
| 552 | 91 | $PageRetriever = $this->newCachedPageRetriever(); |
|
| 553 | |||
| 554 | 91 | return $this->addProfilingDecorator( $PageRetriever, 'PageRetriever' ); |
|
| 555 | } |
||
| 556 | |||
| 557 | 91 | private function newCachedPageRetriever(): PageRetriever { |
|
| 558 | 91 | return new CachingPageRetriever( |
|
| 559 | 91 | $this->newNonCachedApiPageRetriever(), |
|
| 560 | 91 | $this->getPageCache() |
|
| 561 | ); |
||
| 562 | } |
||
| 563 | |||
| 564 | 91 | private function newNonCachedApiPageRetriever(): PageRetriever { |
|
| 565 | 91 | return new ApiBasedPageRetriever( |
|
| 566 | 91 | $this->getMediaWikiApi(), |
|
| 567 | 91 | new ApiUser( $this->config['cms-wiki-user'], $this->config['cms-wiki-password'] ), |
|
| 568 | 91 | $this->getLogger(), |
|
| 569 | 91 | $this->config['cms-wiki-title-prefix'] |
|
| 570 | ); |
||
| 571 | } |
||
| 572 | |||
| 573 | 100 | public function getLogger(): LoggerInterface { |
|
| 574 | 100 | return $this->pimple['logger']; |
|
| 575 | } |
||
| 576 | |||
| 577 | 88 | private function getVarPath(): string { |
|
| 578 | 88 | return __DIR__ . '/../../var'; |
|
| 579 | } |
||
| 580 | |||
| 581 | 88 | public function getCachePath(): string { |
|
| 582 | 88 | return $this->getVarPath() . '/cache'; |
|
| 583 | } |
||
| 584 | |||
| 585 | public function getLoggingPath(): string { |
||
| 586 | return $this->getVarPath() . '/log'; |
||
| 587 | } |
||
| 588 | |||
| 589 | public function getTemplatePath(): string { |
||
| 590 | return __DIR__ . '/../../app/templates'; |
||
| 591 | } |
||
| 592 | |||
| 593 | 6 | public function newAddSubscriptionUseCase(): AddSubscriptionUseCase { |
|
| 594 | 6 | return new AddSubscriptionUseCase( |
|
| 595 | 6 | $this->getSubscriptionRepository(), |
|
| 596 | 6 | $this->getSubscriptionValidator(), |
|
| 597 | 6 | $this->newAddSubscriptionMailer() |
|
| 598 | ); |
||
| 599 | } |
||
| 600 | |||
| 601 | 3 | public function newConfirmSubscriptionUseCase(): ConfirmSubscriptionUseCase { |
|
| 602 | 3 | return new ConfirmSubscriptionUseCase( |
|
| 603 | 3 | $this->getSubscriptionRepository(), |
|
| 604 | 3 | $this->newConfirmSubscriptionMailer() |
|
| 605 | ); |
||
| 606 | } |
||
| 607 | |||
| 608 | 6 | private function newAddSubscriptionMailer(): TemplateBasedMailer { |
|
| 609 | 6 | return $this->newTemplateMailer( |
|
| 610 | 6 | new TwigTemplate( |
|
| 611 | 6 | $this->getTwig(), |
|
| 612 | 6 | 'Mail_Subscription_Request.twig', |
|
| 613 | [ |
||
| 614 | 6 | 'basepath' => $this->config['web-basepath'], |
|
| 615 | 6 | 'greeting_generator' => $this->getGreetingGenerator() |
|
| 616 | ] |
||
| 617 | ), |
||
| 618 | 6 | 'mail_subject_membership' |
|
| 619 | ); |
||
| 620 | } |
||
| 621 | |||
| 622 | 3 | private function newConfirmSubscriptionMailer(): TemplateBasedMailer { |
|
| 623 | 3 | return $this->newTemplateMailer( |
|
| 624 | 3 | new TwigTemplate( |
|
| 625 | 3 | $this->getTwig(), |
|
| 626 | 3 | 'Mail_Subscription_Confirmation.twig', |
|
| 627 | 3 | [ 'greeting_generator' => $this->getGreetingGenerator() ] |
|
| 628 | ), |
||
| 629 | 3 | 'mail_subject_membership' |
|
| 630 | ); |
||
| 631 | } |
||
| 632 | |||
| 633 | 45 | private function newTemplateMailer( TwigTemplate $template, string $messageKey ): TemplateBasedMailer { |
|
| 634 | 45 | $mailer = new TemplateBasedMailer( |
|
| 635 | 45 | $this->getMessenger(), |
|
| 636 | $template, |
||
| 637 | 45 | $this->getTranslator()->trans( $messageKey ) |
|
| 638 | ); |
||
| 639 | |||
| 640 | 45 | $mailer = new LoggingMailer( $mailer, $this->getLogger() ); |
|
| 641 | |||
| 642 | 45 | return $this->addProfilingDecorator( $mailer, 'Mailer' ); |
|
| 643 | } |
||
| 644 | |||
| 645 | 42 | public function getGreetingGenerator() { |
|
| 646 | 42 | return $this->pimple['greeting_generator']; |
|
| 647 | } |
||
| 648 | |||
| 649 | public function newCheckIbanUseCase(): CheckIbanUseCase { |
||
| 650 | return new CheckIbanUseCase( $this->newBankDataConverter(), $this->newIbanValidator() ); |
||
| 651 | } |
||
| 652 | |||
| 653 | public function newGenerateIbanUseCase(): GenerateIbanUseCase { |
||
| 654 | return new GenerateIbanUseCase( $this->newBankDataConverter(), $this->newIbanValidator() ); |
||
| 655 | } |
||
| 656 | |||
| 657 | public function newIbanPresenter(): IbanPresenter { |
||
| 658 | return new IbanPresenter(); |
||
| 659 | } |
||
| 660 | |||
| 661 | 23 | public function newBankDataConverter() { |
|
| 662 | 23 | return new BankDataConverter( $this->config['bank-data-file'] ); |
|
| 663 | } |
||
| 664 | |||
| 665 | public function setSubscriptionValidator( SubscriptionValidator $subscriptionValidator ) { |
||
| 666 | $this->pimple['subscription_validator'] = $subscriptionValidator; |
||
| 667 | } |
||
| 668 | |||
| 669 | public function setPageTitlePrefix( string $prefix ) { |
||
| 670 | $this->config['cms-wiki-title-prefix'] = $prefix; |
||
| 671 | } |
||
| 672 | |||
| 673 | 3 | public function newGetInTouchUseCase() { |
|
| 674 | 3 | return new GetInTouchUseCase( |
|
| 675 | 3 | $this->getContactValidator(), |
|
| 676 | 3 | $this->newContactOperatorMailer(), |
|
| 677 | 3 | $this->newContactUserMailer() |
|
| 678 | ); |
||
| 679 | } |
||
| 680 | |||
| 681 | 3 | private function newContactUserMailer(): TemplateBasedMailer { |
|
| 682 | 3 | return $this->newTemplateMailer( |
|
| 683 | 3 | new TwigTemplate( $this->getTwig(), 'KontaktMailExtern.twig' ), |
|
| 684 | 3 | 'mail_subject_getintouch' |
|
| 685 | ); |
||
| 686 | } |
||
| 687 | |||
| 688 | 3 | private function newContactOperatorMailer(): TemplateBasedMailer { |
|
| 689 | 3 | return $this->newTemplateMailer( |
|
| 690 | 3 | new TwigTemplate( $this->getTwig(), 'KontaktMailIntern.twig' ), |
|
| 691 | 3 | 'mail_subject_getintouch_forward' |
|
| 692 | ); |
||
| 693 | } |
||
| 694 | |||
| 695 | 3 | private function getContactValidator(): GetInTouchValidator { |
|
| 696 | 3 | return $this->pimple['contact_validator']; |
|
| 697 | } |
||
| 698 | |||
| 699 | 6 | private function newSubscriptionDuplicateValidator(): SubscriptionDuplicateValidator { |
|
| 700 | 6 | return new SubscriptionDuplicateValidator( |
|
| 701 | 6 | $this->getSubscriptionRepository(), |
|
| 702 | 6 | $this->newSubscriptionDuplicateCutoffDate() |
|
| 703 | ); |
||
| 704 | } |
||
| 705 | |||
| 706 | 6 | private function newSubscriptionDuplicateCutoffDate(): \DateTime { |
|
| 707 | 6 | $cutoffDateTime = new \DateTime(); |
|
| 708 | 6 | $cutoffDateTime->sub( new \DateInterval( $this->config['subscription-interval'] ) ); |
|
| 709 | 6 | return $cutoffDateTime; |
|
| 710 | } |
||
| 711 | |||
| 712 | 6 | private function newHonorificValidator(): AllowedValuesValidator { |
|
| 713 | 6 | return new AllowedValuesValidator( $this->getHonorifics()->getKeys() ); |
|
| 714 | } |
||
| 715 | |||
| 716 | 67 | private function getHonorifics(): Honorifics { |
|
| 717 | 67 | return $this->pimple['honorifics']; |
|
| 718 | } |
||
| 719 | |||
| 720 | 1 | public function newAuthorizedCachePurger(): AuthorizedCachePurger { |
|
| 721 | 1 | return new AuthorizedCachePurger( |
|
| 722 | 1 | new AllOfTheCachePurger( $this->getTwig(), $this->getPageCache() ), |
|
| 723 | 1 | $this->config['purging-secret'] |
|
| 724 | ); |
||
| 725 | } |
||
| 726 | |||
| 727 | 23 | private function newBankDataValidator(): BankDataValidator { |
|
| 728 | 23 | return new BankDataValidator( $this->newIbanValidator() ); |
|
| 729 | } |
||
| 730 | |||
| 731 | 45 | private function getMessenger(): Messenger { |
|
| 732 | 45 | return $this->pimple['messenger']; |
|
| 733 | } |
||
| 734 | |||
| 735 | 43 | public function setMessenger( Messenger $messenger ) { |
|
| 736 | 43 | $this->pimple['messenger'] = $messenger; |
|
| 737 | 43 | } |
|
| 738 | |||
| 739 | 42 | public function setNullMessenger() { |
|
| 740 | 42 | $this->setMessenger( new Messenger( |
|
| 741 | 42 | Swift_NullTransport::newInstance(), |
|
| 742 | 42 | $this->getOperatorAddress() |
|
| 743 | ) ); |
||
| 744 | 42 | } |
|
| 745 | |||
| 746 | 47 | public function getOperatorAddress() { |
|
| 749 | |||
| 750 | 9 | public function newInternalErrorHTMLPresenter(): InternalErrorHtmlPresenter { |
|
| 753 | |||
| 754 | 3 | public function newAccessDeniedHTMLPresenter(): InternalErrorHtmlPresenter { |
|
| 757 | |||
| 758 | 95 | public function getTranslator(): TranslatorInterface { |
|
| 761 | |||
| 762 | 2 | public function setTranslator( TranslatorInterface $translator ) { |
|
| 763 | 2 | $this->pimple['translator'] = $translator; |
|
| 764 | 2 | } |
|
| 765 | |||
| 766 | 88 | private function getTwigFactory(): TwigFactory { |
|
| 769 | |||
| 770 | 24 | private function newTextPolicyValidator( string $policyName ): TextPolicyValidator { |
|
| 771 | 24 | $contentProvider = $this->newWikiPageRetriever(); |
|
| 772 | 24 | $textPolicyConfig = $this->config['text-policies'][$policyName]; |
|
| 773 | |||
| 774 | 24 | return new TextPolicyValidator( |
|
| 775 | 24 | new PageRetrieverBasedStringList( $contentProvider, $textPolicyConfig['badwords'] ?? '' ), |
|
| 776 | 24 | new PageRetrieverBasedStringList( $contentProvider, $textPolicyConfig['whitewords'] ?? '' ) |
|
| 777 | ); |
||
| 778 | } |
||
| 779 | |||
| 780 | 3 | private function newCommentPolicyValidator(): TextPolicyValidator { |
|
| 783 | |||
| 784 | 5 | public function newCancelDonationUseCase( string $updateToken ): CancelDonationUseCase { |
|
| 785 | 5 | return new CancelDonationUseCase( |
|
| 786 | 5 | $this->getDonationRepository(), |
|
| 787 | 5 | $this->newCancelDonationMailer(), |
|
| 788 | 5 | $this->newDonationAuthorizer( $updateToken ), |
|
| 789 | 5 | $this->newDonationEventLogger() |
|
| 790 | ); |
||
| 791 | } |
||
| 792 | |||
| 793 | 5 | private function newCancelDonationMailer(): TemplateBasedMailer { |
|
| 803 | |||
| 804 | 15 | public function newAddDonationUseCase(): AddDonationUseCase { |
|
| 805 | 15 | return new AddDonationUseCase( |
|
| 806 | 15 | $this->getDonationRepository(), |
|
| 807 | 15 | $this->newDonationValidator(), |
|
| 808 | 15 | $this->newDonationPolicyValidator(), |
|
| 809 | 15 | $this->newReferrerGeneralizer(), |
|
| 810 | 15 | $this->newDonationConfirmationMailer(), |
|
| 811 | 15 | $this->newBankTransferCodeGenerator(), |
|
| 812 | 15 | $this->newDonationTokenFetcher() |
|
| 813 | ); |
||
| 814 | } |
||
| 815 | |||
| 816 | 15 | private function newBankTransferCodeGenerator(): TransferCodeGenerator { |
|
| 817 | 15 | return new UniqueTransferCodeGenerator( |
|
| 818 | 15 | new SimpleTransferCodeGenerator(), |
|
| 819 | 15 | $this->getEntityManager() |
|
| 820 | ); |
||
| 821 | } |
||
| 822 | |||
| 823 | 15 | private function newDonationValidator(): AddDonationValidator { |
|
| 824 | 15 | return new AddDonationValidator( |
|
| 825 | 15 | $this->newPaymentDataValidator(), |
|
| 826 | 15 | $this->newBankDataValidator(), |
|
| 827 | 15 | $this->getEmailValidator() |
|
| 828 | ); |
||
| 829 | } |
||
| 830 | |||
| 831 | 2 | public function newPersonalInfoValidator(): DonorValidator { |
|
| 838 | |||
| 839 | 18 | private function newDonationConfirmationMailer(): DonationConfirmationMailer { |
|
| 840 | 18 | return new DonationConfirmationMailer( |
|
| 841 | 18 | $this->newTemplateMailer( |
|
| 842 | 18 | new TwigTemplate( |
|
| 843 | 18 | $this->getTwig(), |
|
| 844 | 18 | 'Mail_Donation_Confirmation.twig', // TODO: ongoing unification of different templates |
|
| 845 | [ |
||
| 846 | 18 | 'basepath' => $this->config['web-basepath'], |
|
| 847 | 18 | 'greeting_generator' => $this->getGreetingGenerator() |
|
| 848 | ] |
||
| 849 | ), |
||
| 850 | 18 | 'mail_subject_confirm_donation' |
|
| 851 | ) |
||
| 852 | ); |
||
| 853 | } |
||
| 854 | |||
| 855 | 1 | public function newPayPalUrlGenerator() { |
|
| 858 | |||
| 859 | 1 | private function getPayPalUrlConfig() { |
|
| 860 | 1 | return PayPalUrlConfig::newFromConfig( $this->config['paypal'] ); |
|
| 861 | } |
||
| 862 | |||
| 863 | 2 | private function newCreditCardUrlGenerator() { |
|
| 866 | |||
| 867 | 2 | private function newCreditCardUrlConfig() { |
|
| 870 | |||
| 871 | 36 | public function getDonationRepository(): DonationRepository { |
|
| 874 | |||
| 875 | 26 | public function newPaymentDataValidator(): PaymentDataValidator { |
|
| 876 | 26 | return new PaymentDataValidator( $this->config['donation-minimum-amount'], $this->config['donation-maximum-amount'] ); |
|
| 877 | } |
||
| 878 | |||
| 879 | 13 | private function newAmountFormatter(): AmountFormatter { |
|
| 882 | |||
| 883 | 2 | public function newDecimalNumberFormatter(): NumberFormatter { |
|
| 886 | |||
| 887 | 3 | public function newAddCommentUseCase( string $updateToken ): AddCommentUseCase { |
|
| 888 | 3 | return new AddCommentUseCase( |
|
| 889 | 3 | $this->getDonationRepository(), |
|
| 890 | 3 | $this->newDonationAuthorizer( $updateToken ), |
|
| 891 | 3 | $this->newCommentPolicyValidator(), |
|
| 892 | 3 | $this->newAddCommentValidator() |
|
| 893 | ); |
||
| 894 | } |
||
| 895 | |||
| 896 | 22 | private function newDonationAuthorizer( string $updateToken = null, string $accessToken = null ): DonationAuthorizer { |
|
| 897 | 22 | return new DoctrineDonationAuthorizer( |
|
| 898 | 22 | $this->getEntityManager(), |
|
| 899 | $updateToken, |
||
| 900 | $accessToken |
||
| 901 | ); |
||
| 902 | } |
||
| 903 | |||
| 904 | 74 | public function getTokenGenerator(): TokenGenerator { |
|
| 907 | |||
| 908 | 8 | public function newDonationConfirmationPresenter() { |
|
| 909 | 8 | return new DonationConfirmationHtmlPresenter( |
|
| 910 | 8 | $this->getIncludeTemplate( 'DonationConfirmation.twig', [ 'piwikGoals' => [ 3 ] ] ) |
|
| 911 | ); |
||
| 912 | } |
||
| 913 | |||
| 914 | 2 | public function newCreditCardPaymentHtmlPresenter() { |
|
| 915 | 2 | return new CreditCardPaymentHtmlPresenter( |
|
| 916 | 2 | $this->getIncludeTemplate( 'CreditCardPaymentIframe.twig' ), |
|
| 917 | 2 | $this->getTranslator(), |
|
| 918 | 2 | $this->newCreditCardUrlGenerator() |
|
| 919 | ); |
||
| 920 | } |
||
| 921 | |||
| 922 | 5 | public function newCancelDonationHtmlPresenter() { |
|
| 923 | 5 | return new CancelDonationHtmlPresenter( |
|
| 924 | 5 | $this->getIncludeTemplate( 'Donation_Cancellation_Confirmation.twig' ) |
|
| 925 | ); |
||
| 926 | } |
||
| 927 | |||
| 928 | 8 | public function newApplyForMembershipUseCase(): ApplyForMembershipUseCase { |
|
| 929 | 8 | return new ApplyForMembershipUseCase( |
|
| 930 | 8 | $this->getMembershipApplicationRepository(), |
|
| 931 | 8 | $this->newMembershipApplicationTokenFetcher(), |
|
| 932 | 8 | $this->newApplyForMembershipMailer(), |
|
| 933 | 8 | $this->newMembershipApplicationValidator(), |
|
| 934 | 8 | $this->newMembershipApplicationTracker(), |
|
| 935 | 8 | $this->newMembershipApplicationPiwikTracker() |
|
| 936 | ); |
||
| 937 | } |
||
| 938 | |||
| 939 | 8 | private function newApplyForMembershipMailer(): TemplateBasedMailer { |
|
| 949 | |||
| 950 | 8 | private function newMembershipApplicationValidator(): MembershipApplicationValidator { |
|
| 957 | |||
| 958 | 8 | private function newMembershipApplicationTracker(): ApplicationTracker { |
|
| 961 | |||
| 962 | 8 | private function newMembershipApplicationPiwikTracker(): ApplicationPiwikTracker { |
|
| 965 | |||
| 966 | 2 | public function newCancelMembershipApplicationUseCase( string $updateToken ): CancelMembershipApplicationUseCase { |
|
| 967 | 2 | return new CancelMembershipApplicationUseCase( |
|
| 968 | 2 | $this->newMembershipApplicationAuthorizer( $updateToken ), |
|
| 969 | 2 | $this->getMembershipApplicationRepository(), |
|
| 970 | 2 | $this->newCancelMembershipApplicationMailer() |
|
| 971 | ); |
||
| 972 | } |
||
| 973 | |||
| 974 | 2 | private function newMembershipApplicationAuthorizer( |
|
| 975 | string $updateToken = null, string $accessToken = null ): ApplicationAuthorizer { |
||
| 976 | |||
| 977 | 2 | return new DoctrineApplicationAuthorizer( |
|
| 978 | 2 | $this->getEntityManager(), |
|
| 979 | $updateToken, |
||
| 980 | $accessToken |
||
| 981 | ); |
||
| 982 | } |
||
| 983 | |||
| 984 | 10 | public function getMembershipApplicationRepository(): ApplicationRepository { |
|
| 985 | 10 | return $this->pimple['membership_application_repository']; |
|
| 986 | } |
||
| 987 | |||
| 988 | 2 | private function newCancelMembershipApplicationMailer(): TemplateBasedMailer { |
|
| 989 | 2 | return $this->newTemplateMailer( |
|
| 990 | 2 | new TwigTemplate( |
|
| 991 | 2 | $this->getTwig(), |
|
| 998 | |||
| 999 | public function newMembershipApplicationConfirmationUseCase( string $accessToken ) { |
||
| 1005 | |||
| 1006 | 11 | public function newShowDonationConfirmationUseCase( string $accessToken ): ShowDonationConfirmationUseCase { |
|
| 1007 | 11 | return new ShowDonationConfirmationUseCase( |
|
| 1008 | 11 | $this->newDonationAuthorizer( null, $accessToken ), |
|
| 1009 | 11 | $this->newDonationTokenFetcher(), |
|
| 1010 | 11 | $this->getDonationRepository() |
|
| 1011 | ); |
||
| 1012 | } |
||
| 1013 | |||
| 1014 | 7 | public function setDonationConfirmationPageSelector( DonationConfirmationPageSelector $selector ) { |
|
| 1015 | 7 | $this->pimple['confirmation-page-selector'] = $selector; |
|
| 1016 | 7 | } |
|
| 1017 | |||
| 1018 | 18 | public function getDonationConfirmationPageSelector() { |
|
| 1019 | 18 | return $this->pimple['confirmation-page-selector']; |
|
| 1020 | } |
||
| 1021 | |||
| 1022 | 3 | public function newDonationFormViolationPresenter() { |
|
| 1023 | // TODO make the template name dependent on the 'form' value from the HTTP POST request |
||
| 1024 | // (we need different form pages for A/B testing) |
||
| 1025 | 3 | $template = $this->getLayoutTemplate( 'DisplayPageLayout.twig', [ 'main_template' => 'DonationForm.twig' ] ); |
|
| 1026 | 3 | return new DonationFormViolationPresenter( $template, $this->newAmountFormatter() ); |
|
| 1027 | } |
||
| 1028 | |||
| 1029 | 10 | public function newDonationFormPresenter() { |
|
| 1030 | // TODO make the template name dependent on the 'form' value from the HTTP POST request |
||
| 1031 | // (we need different form pages for A/B testing) |
||
| 1032 | 10 | $template = $this->getLayoutTemplate( 'DisplayPageLayout.twig', [ 'main_template' => 'DonationForm.twig' ] ); |
|
| 1033 | 10 | return new DonationFormPresenter( $template, $this->newAmountFormatter() ); |
|
| 1034 | } |
||
| 1035 | |||
| 1036 | 1 | public function newHandlePayPalPaymentNotificationUseCase( string $updateToken ) { |
|
| 1045 | |||
| 1046 | 2 | public function getPayPalPaymentNotificationVerifier(): PaymentNotificationVerifier { |
|
| 1049 | |||
| 1050 | 2 | public function setPayPalPaymentNotificationVerifier( PaymentNotificationVerifier $verifier ) { |
|
| 1053 | |||
| 1054 | 2 | public function newCreditCardNotificationUseCase( string $updateToken ) { |
|
| 1064 | |||
| 1065 | 2 | public function newCancelMembershipApplicationHtmlPresenter() { |
|
| 1070 | |||
| 1071 | public function newMembershipApplicationConfirmationHtmlPresenter() { |
||
| 1076 | |||
| 1077 | 2 | public function newMembershipFormViolationPresenter() { |
|
| 1082 | |||
| 1083 | 2 | public function setCreditCardService( CreditCardService $ccService ) { |
|
| 1086 | |||
| 1087 | 2 | public function getCreditCardService(): CreditCardService { |
|
| 1090 | |||
| 1091 | 2 | public function newCreditCardNotificationPresenter(): CreditCardNotificationPresenter { |
|
| 1100 | |||
| 1101 | 74 | private function newDoctrineDonationPrePersistSubscriber(): DoctrineDonationPrePersistSubscriber { |
|
| 1108 | |||
| 1109 | 74 | private function newDoctrineMembershipApplicationPrePersistSubscriber(): DoctrineMembershipApplicationPrePersistSubscriber { |
|
| 1116 | |||
| 1117 | 17 | public function setTokenGenerator( TokenGenerator $tokenGenerator ) { |
|
| 1120 | |||
| 1121 | public function disableDoctrineSubscribers() { |
||
| 1124 | |||
| 1125 | 24 | private function newDonationTokenFetcher(): DonationTokenFetcher { |
|
| 1130 | |||
| 1131 | 8 | private function newMembershipApplicationTokenFetcher(): ApplicationTokenFetcher { |
|
| 1136 | |||
| 1137 | 15 | private function newDonationPolicyValidator(): AddDonationPolicyValidator { |
|
| 1143 | |||
| 1144 | 15 | private function newDonationAmountPolicyValidator(): AmountPolicyValidator { |
|
| 1148 | |||
| 1149 | 2 | public function getDonationTimeframeLimit() { |
|
| 1152 | |||
| 1153 | 2 | public function newSystemMessageResponse( string $message ) { |
|
| 1157 | |||
| 1158 | 2 | public function getMembershipApplicationTimeframeLimit() { |
|
| 1161 | |||
| 1162 | 3 | private function newAddCommentValidator(): AddCommentValidator { |
|
| 1165 | |||
| 1166 | 91 | private function getPageCache(): Cache { |
|
| 1169 | |||
| 1170 | public function enablePageCache() { |
||
| 1175 | |||
| 1176 | 97 | private function addProfilingDecorator( $objectToDecorate, string $profilingLabel ) { |
|
| 1185 | |||
| 1186 | public function setProfiler( Stopwatch $profiler ) { |
||
| 1189 | |||
| 1190 | public function setLogger( LoggerInterface $logger ) { |
||
| 1193 | |||
| 1194 | public function getProfilerDataCollector(): ProfilerDataCollector { |
||
| 1197 | |||
| 1198 | 23 | private function newIbanValidator(): IbanValidator { |
|
| 1199 | 23 | return new IbanValidator( $this->newBankDataConverter(), $this->config['banned-ibans'] ); |
|
| 1200 | } |
||
| 1201 | |||
| 1202 | 88 | private function newFilePrefixer(): FilePrefixer { |
|
| 1203 | 88 | return new FilePrefixer( $this->getFilePrefix() ); |
|
| 1204 | } |
||
| 1205 | |||
| 1206 | 88 | private function getFilePrefix(): string { |
|
| 1207 | 88 | $prefixContentFile = $this->getVarPath() . '/file_prefix.txt'; |
|
| 1208 | 88 | if ( !file_exists( $prefixContentFile ) ) { |
|
| 1209 | 88 | return ''; |
|
| 1210 | } |
||
| 1211 | return $prefix = preg_replace( '/[^0-9a-f]/', '', file_get_contents( $prefixContentFile ) ); |
||
|
|
|||
| 1212 | } |
||
| 1213 | |||
| 1214 | } |
||
| 1215 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.