GithubHelp home page GithubHelp logo

Guidelines are incomplete about zubr HOT 12 CLOSED

nkkollaw avatar nkkollaw commented on July 19, 2024
Guidelines are incomplete

from zubr.

Comments (12)

nkkollaw avatar nkkollaw commented on July 19, 2024 1

Kahlan stubs on php functions works only when you test psr0 / psr4 classes - it mocks composer autoloader. So it will not work with functions
In this case, we can simply create a class with static methods instead of separate functions.

Should we move the conversation to #2 ..?

UNRELEATED: are we all in Poland? :-)
I am. Dunno about you folks :)

Wrocław here (although I'm Italian).

from zubr.

ddziaduch avatar ddziaduch commented on July 19, 2024 1

Gdańsk here

from zubr.

radmen avatar radmen commented on July 19, 2024

The thing that bothers me in PHP: convention of "segments" order in a function name.

Eg. there's urldecode() and parse_url(). First one is in format: $SUBJECT$ACTION, second in: $ACTION_$SUBJECT.

If it makes sense I'd like to unify this to a common format: $SUBJECT_$ACTION(). This would result in renaming parse_url() to url_parse().

What do you think about it?

from zubr.

nkkollaw avatar nkkollaw commented on July 19, 2024

I see what you mean, and I agree that it's not great.

I think however that we should keep function names the same, so that one doesn't have to relearn the language. What I mean is that if I know PHP's build-in function is strpos, I can expect its equivalent to be \PHP\str_pos, and for parse_url I'd expect it to be in \PHP\parse_url, not \PHP\url_parse.

My idea is to create a wrapper to PHP build-in functions that changed as little as possible, so that it can be very intuitive to use. I do think that we can use aliases, but they should probably be used as little as possible.

What do you think instead of the concept of plugin? We could have something like this, in this case a plugin called "fix-common-format" let's say, that fixed all the functions by doing:

\PHP\PHP::addAlias('url_parse', function($url) {
    return parse_url($url);
});

Then we could use magic methods to catch url_parse and call the function provided by the plugin. Just an idea but it would allow to "pick" fixes that one is interested in, and would allow adding many aliases without "polluting" regular names.

from zubr.

radmen avatar radmen commented on July 19, 2024

I think however that we should keep function names the same, so that one doesn't have to relearn the language. What I mean is that if I know PHP's build-in function is strpos, I can expect its equivalent to be \PHP\str_pos, and for parse_url I'd expect it to be in \PHP\parse_url, not \PHP\url_parse.

Good catch. It makes sense to keep the naming as you suggest.

What do you think instead of the concept of plugin? We could have something like this, in this case a plugin called "fix-common-format" let's say, that fixed all the functions by doing:

I'd say that we shouldn't complicate things. If the library is meant to be a wrapper with sane functions API it should stay that way.

Plugins may be next step, but definitely not now.

from zubr.

nkkollaw avatar nkkollaw commented on July 19, 2024

Plugins may be next step, but definitely not now.

I agree.

I think the priority is consistent naming (underscore) and argument order. We should tackle consistent error reporting as well (returning false vs. throwing exception vs. doing nothing), but perhaps in the future.

Do you have anything to add to the guidelines? I think it's us 2 so far, let's do this! :-)

from zubr.

radmen avatar radmen commented on July 19, 2024

IMO theses Guidelines are enough to start.

from zubr.

nkkollaw avatar nkkollaw commented on July 19, 2024

OK.

I'll add some more functions today. Would you want to feel like creating a stub for tests?

from zubr.

ddziaduch avatar ddziaduch commented on July 19, 2024

@nkkollaw I tried to add Kahlan yesterday. But Kahlan stubs on php functions works only when you test psr0 / psr4 classes - it mocks composer autoloader. So it will not work with functions :(

from zubr.

nkkollaw avatar nkkollaw commented on July 19, 2024

@ddziaduch : that sucks, but thanks for trying.

Perhaps we can create a wrapper class, that simply calls our function(s)?

UNRELEATED: are we all in Poland? :-)

from zubr.

radmen avatar radmen commented on July 19, 2024

Kahlan stubs on php functions works only when you test psr0 / psr4 classes - it mocks composer autoloader. So it will not work with functions

In this case, we can simply create a class with static methods instead of separate functions.

UNRELEATED: are we all in Poland? :-)

I am. Dunno about you folks :)

from zubr.

nkkollaw avatar nkkollaw commented on July 19, 2024

Closing this as we've established that guidelines in the README are enough to start.

from zubr.

Related Issues (20)

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.