Open zupo opened 6 years ago
Enums in PHP
<?php
trait EnumHelpers {
public static function getValues(){
return (new ReflectionClass(get_called_class()))->getConstants();
}
}
class Themes {
use EnumHelpers;
const BookStore = "bookstore";
const ToyStore = "toystore";
}
var_dump(Themes::BookStore);
var_dump(Themes::getValues());
?>
@zupo tried option B; would be nice if you could take a look.
What's the next step here?
The Story
As a Victor, I never want to see wrong theme name bug again, because it is completely preventable.
Problem
Theme names are hardcoded in CartFront theme and not checked against the valid values defined in openapi.yaml schema.
Proposal
Before you start: It's
Bookstore
, notBooks Store
orBook Store
. Use search & replace to fix all codebase.Option A:
$stores
array into an enummake codegen
command that generates the$stores
enum fromtemplate
values on https://app.woocart.com/api/v1/openapi.yaml.make codegen
changes filesOption B:
make validate
command that validates values of$stores
array againsttemplate
values on https://app.woocart.com/api/v1/openapi.yamlmake validate
on Travis so the build fails if values do not matchPitfalls
Best practices (DoD)
Expectations (AC)
Books Store
was refactored toBookstore
.theme
values in CartFront do not matchtemplate
values in openapi.yaml spec.