What are the Slack Archives?

It’s a history of our time together in the Slack Community! There’s a ton of knowledge in here, so feel free to search through the archives for a possible answer to your question.

Because this space is not active, you won’t be able to create a new post or comment here. If you have a question or want to start a discussion about something, head over to our categories and pick one to post in! You can always refer back to a post from Slack Archives if needed; just copy the link to use it as a reference..

I'm running the architecture sniffer and getting an error that I don't understand. It's about attach

U01LKKBK97T
U01LKKBK97T Posts: 287 πŸ§‘πŸ»β€πŸš€ - Cadet

I'm running the architecture sniffer and getting an error that I don't understand. It's about attached interface and its implementation. Command output keeps telling me that the bridge method is different from the one defined in the interface.

docker/sdk console code:sniff:architecture -vvv
-->  DEVELOPMENT MODE   
Store: DE | Environment: docker.dev
Run Architecture Sniffer for PROJECT
/data/src/
 Bridges: The bridge interface has incorrect method 'generate' signature. That violates the rule "All bridge methods must have exactly the same signature as their interface" (l. 12)
 Spryker > BridgeMethodsRule
1 violations found

Next thing I did was to edit vendor/spryker/architecture-sniffer/src/Common/Bridge/BridgeMethodsRule.php temporarily to produce some additional log output. Turns out that the parameter comparison is failing:

Parameter #0 [ <required> Generated\Shared\Transfer\SequenceNumberSettingsTransfer $sequenceNumberSettingsTransfer ]
Parameter #0 [ <required> Generated\Shared\Transfer\SequenceNumberSettingsTransfer $sequenceNumberSettings ]

First line is the one from the interface method, second one from its implementation.
Crazy thing is that the second line doesn't reflect the actual argument name from the Bridge class. How can that be?

Comments

  • U01LKKBK97T
    U01LKKBK97T Posts: 287 πŸ§‘πŸ»β€πŸš€ - Cadet

    Hm, if I rename $sequenceNumberSettingsTransfer to $sequenceNumberSettings in interface and implementation, it will pass validation. Is there a length limitation for var names?

  • Ievgen Varava
    Ievgen Varava Sprykee Posts: 154 πŸ§‘πŸ»β€πŸš€ - Cadet
    for ($i = 0; $i < $countParameters; $i++) {
                if ((string)$firstMethodParameters[$i] !== (string)$secondMethodParameters[$i]) {
                    return false;
                }
            }
    
  • Ievgen Varava
    Ievgen Varava Sprykee Posts: 154 πŸ§‘πŸ»β€πŸš€ - Cadet

    they just have to match

  • U01LKKBK97T
    U01LKKBK97T Posts: 287 πŸ§‘πŸ»β€πŸš€ - Cadet

    They did match, that's the confusing thing actually.

  • Ievgen Varava
    Ievgen Varava Sprykee Posts: 154 πŸ§‘πŸ»β€πŸš€ - Cadet

    strange, some cache maybe?

  • Ievgen Varava
    Ievgen Varava Sprykee Posts: 154 πŸ§‘πŸ»β€πŸš€ - Cadet

    or not synced

  • U01LKKBK97T
    U01LKKBK97T Posts: 287 πŸ§‘πŸ»β€πŸš€ - Cadet

    I cleared all caches several times.
    Sync issues shouldn't be the reason, afaik that is more something happening on Mac OS. I'm working on Ubuntu, never had issues so far.

  • Ievgen Varava
    Ievgen Varava Sprykee Posts: 154 πŸ§‘πŸ»β€πŸš€ - Cadet

    still, makes sense to check if classes do match in container

  • Ievgen Varava
    Ievgen Varava Sprykee Posts: 154 πŸ§‘πŸ»β€πŸš€ - Cadet

    but I guess you're comparing bridge to it's declared interface

  • Ievgen Varava
    Ievgen Varava Sprykee Posts: 154 πŸ§‘πŸ»β€πŸš€ - Cadet

    you chould also take into account SequenceNumberFacadeInterface

  • Ievgen Varava
    Ievgen Varava Sprykee Posts: 154 πŸ§‘πŸ»β€πŸš€ - Cadet

    there it's public function generate(SequenceNumberSettingsTransfer $sequenceNumberSettings);

  • U01LKKBK97T
    U01LKKBK97T Posts: 287 πŸ§‘πŸ»β€πŸš€ - Cadet

    Might be, yes. But honestly, how stupid is that? Transfer vars are called $...Transfer most of the times, all across the code.

  • Ievgen Varava
    Ievgen Varava Sprykee Posts: 154 πŸ§‘πŸ»β€πŸš€ - Cadet

    that's true, some older spryker modules would not pass new sniffers themselves

  • Ievgen Varava
    Ievgen Varava Sprykee Posts: 154 πŸ§‘πŸ»β€πŸš€ - Cadet

    the rule itself makes sense to me, it makes sure that bridge 100% matches facade interface, so that you're not creating adapter instead

  • Ievgen Varava
    Ievgen Varava Sprykee Posts: 154 πŸ§‘πŸ»β€πŸš€ - Cadet

    btw why would you create bridge in project? or is it separate module?

  • U01LKKBK97T
    U01LKKBK97T Posts: 287 πŸ§‘πŸ»β€πŸš€ - Cadet

    But you should be free to choose var names. Forcing somebody to stick to made up var naming conventions seems useless to me.

  • U01LKKBK97T
    U01LKKBK97T Posts: 287 πŸ§‘πŸ»β€πŸš€ - Cadet

    Yes, the bridge is used to call a facade from a different module.

  • Ievgen Varava
    Ievgen Varava Sprykee Posts: 154 πŸ§‘πŸ»β€πŸš€ - Cadet

    bet it was just easier to implement check like this, exact naming doesn't matter for interpreter of course

  • Ievgen Varava
    Ievgen Varava Sprykee Posts: 154 πŸ§‘πŸ»β€πŸš€ - Cadet
    edited June 2021

    imagine you have calculate(int $price, int $tax) in facade but bridge is defined as calculate(int $tax, int $price). It's still two int parameters but logically you would have to swap parameters inside bridge

  • U01LKKBK97T
    U01LKKBK97T Posts: 287 πŸ§‘πŸ»β€πŸš€ - Cadet
    edited June 2021

    Okay, that is a sensible example. You got me convinced.
    Things like these would be much easier to find and fix if the console command gave some useful output, though.