Coder Social home page Coder Social logo

finalizer's Introduction

Finalizer

This library aims at providing simple tools that help deciding whether a class should or shouldn't be declared as final.

Build Status Scrutinizer Code Quality Code Coverage Latest Stable Version Latest Unstable Version

Help/Support

Gitter

Installation

Install via composer:

php composer.phar require ocramius/finalizer:~1.0

Usage

In your console, simply type:

./vendor/bin/finalizer finalizer:check-final-classes path/to/directory
./vendor/bin/finalizer finalizer:check-final-classes also/supports multiple/directories as/parameters

Note that finalizer will take decisions on whether classes should or shouldn't be final depending on the classes defined in the directories that you passed to it.

Additionally, be aware that finalizer will (in its current state) require any of the PHP or Hack files in the given directories and include them via require_once.

Reference

If you need to know more about why I wrote this library, and what kind of decisions it is doing, then please read this blogpost about the usage of the final keyword.

finalizer's People

Contributors

catalinux avatar cordoval avatar marcosdsanchez avatar ocramius avatar rarst avatar simpod avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

finalizer's Issues

Incorrect/unwanted detection of "need to be made extensible"

When running, it correctly found few classes that were missing final.

But it also listed classes in section "Following classes are final and need to be made extensible again:" that contains value objects, symfony controllers etc. and those shouldn't be made final.

Would adding an option to run it only for classes missing final make sense?

Does not work with phalcon

Should it?

I hate phalcon but I had to do some maintenance in a phalcon project and it tries to read the fw classes, since they're imported.

Couldn't someone update it to not look into the imports? Or maybe continue even if the class is missing?

Move to AST-based parsing of provided files

The current API uses require_once, get_declared_classes() and ReflectionClass to inspect the class hierarchies.

This is not viable when the source-code is not PSR-2 compliant, as it may include bits of code that cause side-effects.

Therefore, finalizer should parse the files and re-construct reflection-ish ValueObjects that represent information relevant to it.

Autoloader

Any chance to support an autoloader in the near future ?

De-finalize class particular cases

Let's admit we have an interface like this

interface myInterface
{
    public function foo();
}

Then an abstract class implementing this interface but adding some methods than these defined inside the above interface

abstract class AbstractMyClass implements myInterface
{
    public function foo()
    {
    }

    public function bar()
    {
    }
}

Then we have another simple class that extend this abstract class that only use methods defined inside the interface.

final class myClass extends AbstractMyClass
{
    /**
     * {@inheritdoc}
     */
    public function foo()
    {
        // ...
    }
}

In this case if I made myClass final then Finalizer will say that myClass should be extensible and not final because this condition is not complete

All of the public API of the final class is part of that interface

But myClass is not used to be extenable and will not. This make sense that this class can use the final keyword.

I my case I can't fix it by modifying the interface because this interface and this abstract class are from vendor.

This would be great to add an option to tell Finalizer to check classes that should be de-finalized to avoid this case.

What do you think about that ?
What do you think is the correct way to do in this case ?

make it a phar

actually i was forced to remove the library even in dev because it would require 5.6
maybe like php-cs-fixer it would be good to have it as a phar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.