title: Design pattern to reduce cyclomatic complexity
body: <br />
  I have to send invoices to cutomers through the related customer's API.<br />
  Each customer chooses how to be contacted (email, fax, sms...).<br />
  My problem is that each time I add a new "contact type" I increase the cyclomatic complexity of my script.<br />
  Here is my code :
  <pre><code>&lt;?php
  
  interface ExternalApi
  {
      public function sendByEmail();
      public function sendByFax();
      public function sendBySMS();
      // more sending modes ...
  }
  
  class Api1 implements ExternalApi
  {   
      public function sendByEmail()
      {
          echo __CLASS__.&quot; sending email&lt;br&gt;\n&quot;;
      }
      
      public function sendByFax()
      {
          echo __CLASS__.&quot; sending fax&lt;br&gt;\n&quot;;
      }
      
      public function sendBySMS()
      {
          echo __CLASS__.&quot; sending SMS&lt;br&gt;\n&quot;;
      }
  }
  
  class Customer
  {
      public const EMAIL = 'email';
      public const FAX = 'fax';
      public const SMS = 'sms';
      public const EMAIL_AND_FAX = 'email_and_fax';
      public const PHONE = 'phone';
      public const PLANE = 'plane';
      public const BOAT = 'boat';
      public const SATELITE = 'satelite';
      public const CAB = 'cab';
      // more contact types...
      
      public ?string $contactType;
  }
  
  class Invoice
  {
      public Customer $customer;
      
      public function __construct(Customer $customer)
      {
          $this-&gt;customer = $customer;
      }
  }
  
  class InvoiceSender
  {
      private ExternalApi $api;
  
      public function __construct(ExternalApi $api)
      {
          $this-&gt;api = $api;
      }
      
      public function send(Invoice $invoice)
      {
          switch($invoice-&gt;customer-&gt;contactType) {
              case Customer::EMAIL :
                  $this-&gt;api-&gt;sendByEmail();
                  break;
              case Customer::FAX :
                  $this-&gt;api-&gt;sendByFax();
                  break;
              case Customer::SMS :
                  $this-&gt;api-&gt;sendBySMS();
                  break;
              case Customer::EMAIL_AND_FAX:
                  $this-&gt;api-&gt;sendByEmail();
                  $this-&gt;api-&gt;sendByFax();
                  break;
              // more cases ...
          }
      }
  }
  
  $customer = new Customer();
  $customer-&gt;contactType = Customer::EMAIL_AND_FAX;
  $invoice = new Invoice($customer);
  $api = new Api1();
  $invoiceSender = new InvoiceSender($api);
  $invoiceSender-&gt;send($invoice);
  </code></pre>
  <p>As you can see the switch statement of InvoiceSender::send is increased each time I add a new &quot;contact type&quot;.<br />
  Do you know which design pattern could solve this problem ?</p>