tighten / novapackages

https://novapackages.com
336 stars 61 forks source link

Remove "N4", "v4", "Nova 4", "4", "(4)" From name #212

Closed RhysLees closed 2 years ago

RhysLees commented 2 years ago

I think it would be best to remove any mention of version from Package names and instead encourage people to require nova ^4.0 in their composer.json to show support

marcusmoore commented 2 years ago

I agree and you beat me to creating an issue for it!

RhysLees commented 2 years ago

I agree and you beat me to creating an issue for it!

If I get time this week I might make a PR

RhysLees commented 2 years ago

@marcusmoore If you could point me to the file where its best to trim the names ill submit a pr.

marcusmoore commented 2 years ago

It looks like the replacement is happening in the templates.

I would like to move that code to a presenter method of some sort so we can have a place to put future replacements and write tests around it.

It would be great if you're up for working on it but no pressure (of course 😄 )

RhysLees commented 2 years ago

It looks like the replacement is happening in the templates.

I would like to move that code to a presenter method of some sort so we can have a place to put future replacements and write tests around it.

It would be great if you're up for working on it but no pressure (of course 😄 )

I'll see what I can do!

Just a thought, what if we just make a custom validation rule for name field, that way we don't even save the 'unnecessary data' to db and the user will be displayed an error, which we can tell them to use composer versions to specify support. That would also keep it in one place so we don't duplicate code.

marcusmoore commented 2 years ago

Thanks and no rush @RhysLees 😄

I don't know if I want to reject a package that includes the version in the title but I think we should be more clear about how we determine v4 support. I opened an issue to track that here: #218

RhysLees commented 2 years ago

Thanks and no rush @RhysLees 😄

I don't know if I want to reject a package that includes the version in the title but I think we should be more clear about how we determine v4 support. I opened an issue to track that here: #218

Ah ok, i was going to recommend the following as a rule. would allow is to return feedback to the user when they create the form. This can also be used with a tiny modification to take it out of the array:

    /**
     * Determine if the validation rule passes.
     *
     * @param  string  $attribute
     * @param  mixed  $value
     * @return bool
     */
    public function passes($attribute, $value)
    {
        /**
         * Any item in the haystack that doesn't contain a string needs to be placed at the bottom
         * otherwise it will leave the string before the version number.
         */
        $invalidSubstrings = [
            'N!',
            'V!',
            'Nova !',
            'Nova!',
            '(!)', // Place at bottom
            '!', // Place at bottom
        ];

        // The haystack used to check if the string contains any of the invalid substrings.
        $versionHaystack = [];

        // Create the version haystack for each version of Laravel Nova.
        $v = 1;
        while ($v <= config('novapackages.nova.latest_major_version')) {
            foreach ($invalidSubstrings as $subject) {
                // Replace ! with the version number.
                $versionHaystack[] = str_replace('!', $v, $subject);
            }

            $v++;
        }

        // Filter the value to only contain strings that contain the version number case insensitive.
        $filteredVersions = str_ireplace($versionHaystack, '', $value);

        // Filter extra spaces created by the removing elements from the version haystack.
        $filtered = preg_replace('!\s+!', ' ', $filteredVersions);

        return $filtered === $value;
    }

    /**
     * Get the validation error message.
     *
     * @return string
     */
    public function message()
    {
        return 'The :attribute must not reference a Laravel Nova version. Require the version in your "composer.json".';
    }