Uploaded image for project: 'Couchbase PHP client library'
  1. Couchbase PHP client library
  2. PCBC-513

Consider removing final from PHP classes

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.4.1
    • Fix Version/s: 2.4.2
    • Component/s: None
    • Labels:
      None

      Description

      A lot of classes, including Cluster, Bucket and BucketManager, are marked as final. Since this disables user from extending the classes, it also disables testing frameworks like PHPUnit and Mockery from mocking them.

      This makes it really hard to unit test classes which use any of these final classes. (I can of course work around this by using proxy classes, but it adds a lot of ugly stuff to my codebase.)

      Why were these classes marked as final in the first place? And could it be reverted for the purpose of unit testing/mocking?

        Attachments

        For Gerrit Dashboard: PCBC-513
        # Subject Branch Project Status CR V

          Activity

          Hide
          avsej Sergey Avseyev added a comment -

          I've made them final to protect from extending and possible future API issues.

          Show
          avsej Sergey Avseyev added a comment - I've made them final to protect from extending and possible future API issues.
          Hide
          demontpx Bert Hekman added a comment - - edited

          I'm aware what final does, but I still don't understand why you would mark the classes with it. Isn't it the clients responsibility to make sure the subclass they create are correct? I'm also not sure what you mean by future API issues.

          If you really don't want to remove the final's from the classes, it would also be a possibility to add interfaces to the classes to program against, which would make it a lot easier to mock and unit test.

          Show
          demontpx Bert Hekman added a comment - - edited I'm aware what final does, but I still don't understand why you would mark the classes with it. Isn't it the clients responsibility to make sure the subclass they create are correct? I'm also not sure what you mean by future API issues. If you really don't want to remove the final's from the classes, it would also be a possibility to add interfaces to the classes to program against, which would make it a lot easier to mock and unit test.

            People

            • Assignee:
              avsej Sergey Avseyev
              Reporter:
              demontpx Bert Hekman
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Gerrit Reviews

                There are no open Gerrit changes

                  PagerDuty

                  Error rendering 'com.pagerduty.jira-server-plugin:PagerDuty'. Please contact your Jira administrators.