Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: introduce namespace enum #806

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

tarrow
Copy link
Contributor

@tarrow tarrow commented May 17, 2024

In order to reduce the chance of future mixups lets use an enum for mediawiki namespaces. Athough these namespace ids are not actually globally fixed within the wikibase cloud and wbstack context we force them to be set this way.

Comment on lines 5 to 9
enum MediawikiNamespaces {
public const item = 120;
public const property = 122;
public const lexeme = 146;
}
Copy link
Contributor

@m90 m90 May 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just out of curiosity: why are these living on an enum when they don't use enum features? I.e. right now, this could also be a class and nothing changes as far as I can tell. If it'd be an enum as shown in the docs, it would probably use backed cases:

enum MediawikiNamespace {
    case Item = 120;
    case Property = 122;
    case Lexeme = 146;
}

and \App\Traits\PageFetcher::fetchPagesInNamespace(string $wikiDomain, int $namespace): array could become \App\Traits\PageFetcher::fetchPagesInNamespace(string $wikiDomain, MediawikiNamespace $namespace): array, enforcing expected values at type level already.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great question; I actually switched from an interface to an enum last minute after thinking I was being clever to use a shiny new 8.1 feature but then did it fairly incompetently.

Thanks for the suggestion. Note it was also necessary to explicitly call ->value on the new enum in the PageFetcher

In order to reudce the chance of future mixups lets use
an enum for mediawiki namespaces. Athough these namespace
ids are not actually globally fixed within the wikibase cloud
and wbstack context we force them to be set this way.
Copy link
Contributor

@m90 m90 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

General question: do we cut a release for changes like this because we can or do we wait for something else to ship it?

In case you choose the former, an entry in the changelog would be sweet.

@m90
Copy link
Contributor

m90 commented Jul 11, 2024

@tarrow Any intention on still merging this?

Copy link
Contributor

@rosalieper rosalieper left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will be happy to see this merged

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants