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

API Strongly type return types #558

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

Conversation

emteknetnz
Copy link
Collaborator

@emteknetnz emteknetnz marked this pull request as draft October 15, 2024 05:04
@emteknetnz emteknetnz marked this pull request as ready for review October 21, 2024 21:33
Comment on lines +73 to +74
// These are loosely typed to allow for easy conversion from YAML and backwards compatibility
// e.g. version is likely to be an int, though the DB column it goes into is a Varchar
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
// These are loosely typed to allow for easy conversion from YAML and backwards compatibility
// e.g. version is likely to be an int, though the DB column it goes into is a Varchar

YAML is capable of type inference. I'm fine with not adding strong typing in this update, but I don't think we should include this comment as it implies we shouldn't add strong typing here at any point.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm not sure why you mean by YAML is capable of type inference

The intention here is that developers are likely to define things with the wrong type in YAML, e.g. in workflows.yml we have - 0.2 which is used as a $version param in WorkflowTemplate::__construct(), ironically the default value of that param is '0.0'. The column it goes into is a varchar.

Comment on lines -95 to 120
public function getName()
public function getName(): string
{
return $this->name;
return (string) $this->name;
}

public function getVersion()
public function getVersion(): string
{
return $this->version;
return (string) $this->version;
}

public function getDescription()
public function getDescription(): string
{
return $this->description;
return (string) $this->description;
}

public function getRemindDays()
public function getRemindDays(): int
{
return $this->remindDays;
return (int) $this->remindDays;
}

public function getSort()
public function getSort(): int
{
return $this->sort;
return (int) $this->sort;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why are we adding strong typing here, but not to the properties? Backwards compatibility doesn't seem like a sensible reason on its own, because strong typing is explicitly a breaking change - as as I mentioned above, YAML type inference is very much a thing.

This class isn't a DataObject and doesn't directly interact with DBField, so I'm struggling to see how this is related at all to the issue.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

As mentioned in the comment above, the properties need to be dynamic because it's likely that the types used in YAML are the wrong type, though we don't want people things to break. However we do need to cast to the correct type e.g. DBVarchar will fail validation if an int or float is returned for getVersion()

@GuySartorelli
Copy link
Collaborator

In the interest of getting things merged I'll allow these changes. While I still don't think they're correct, they also don't seem harmful except in that they allow continued poor practice by developers.

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.

2 participants