Skip to content

Commit

Permalink
Use string to const mapping from generated classes.
Browse files Browse the repository at this point in the history
Change-Id: Ib08c505965b7ac72d5b61628e473fe1681508ee0
  • Loading branch information
jfschmakeit committed May 31, 2019
1 parent f45c1dd commit b1b9437
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 95 deletions.
95 changes: 3 additions & 92 deletions src/Google/Photos/Library/V1/FiltersBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,20 +97,7 @@ public function build()
*/
public function setMediaTypeFromString($mediaType)
{
switch ($mediaType) {
case "ALL_MEDIA":
$this->mediaType = MediaType::ALL_MEDIA;
break;
case "PHOTO":
$this->mediaType = MediaType::PHOTO;
break;
case "VIDEO":
$this->mediaType = MediaType::VIDEO;
break;
default:
throw new \InvalidArgumentException($mediaType . " is not a valid MediaType");
}

$this->mediaType = MediaType::value($mediaType);
return $this;
}

Expand All @@ -126,82 +113,6 @@ public function setMediaType($mediaType)
return $this;
}

/**
* Converts a string into a {@link ContentCategory}.
*
* @param string $category A stringified version of a ContentCategory, e.g. "NONE".
* @throws \InvalidArgumentException if $category is not an element of
* {@link PhotosLibraryClient::contentCategories()}.
* @return int A constant from ContentCategory.
*/
private function convertToCategory($category)
{
switch ($category) {
case "NONE":
return ContentCategory::NONE;
break;
case "LANDSCAPES":
return ContentCategory::LANDSCAPES;
break;
case "RECEIPTS":
return ContentCategory::RECEIPTS;
break;
case "CITYSCAPES":
return ContentCategory::CITYSCAPES;
break;
case "LANDMARKS":
return ContentCategory::LANDMARKS;
break;
case "SELFIES":
return ContentCategory::SELFIES;
break;
case "PEOPLE":
return ContentCategory::PEOPLE;
break;
case "PETS":
return ContentCategory::PETS;
break;
case "WEDDINGS":
return ContentCategory::WEDDINGS;
break;
case "BIRTHDAYS":
return ContentCategory::BIRTHDAYS;
break;
case "DOCUMENTS":
return ContentCategory::DOCUMENTS;
break;
case "TRAVEL":
return ContentCategory::TRAVEL;
break;
case "ANIMALS":
return ContentCategory::ANIMALS;
break;
case "FOOD":
return ContentCategory::FOOD;
break;
case "SPORT":
return ContentCategory::SPORT;
break;
case "NIGHT":
return ContentCategory::NIGHT;
break;
case "PERFORMANCES":
return ContentCategory::PERFORMANCES;
break;
case "WHITEBOARDS":
return ContentCategory::WHITEBOARDS;
break;
case "SCREENSHOTS":
return ContentCategory::SCREENSHOTS;
break;
case "UTILITY":
return ContentCategory::UTILITY;
break;
default:
throw new \InvalidArgumentException($category . " is not a valid category.");
}
}

/**
* Adds a category to the list of included categories.
*
Expand All @@ -223,7 +134,7 @@ public function addIncludedCategory($category)
*/
public function addIncludedCategoryFromString($category)
{
return $this->addIncludedCategory($this->convertToCategory($category));
return $this->addIncludedCategory(ContentCategory::value($category));
}

/**
Expand Down Expand Up @@ -271,7 +182,7 @@ public function addExcludedCategory($category)
*/
public function addExcludedCategoryFromString($category)
{
return $this->addExcludedCategory($this->convertToCategory($category));
return $this->addExcludedCategory(ContentCategory::value($category));
}

/**
Expand Down
6 changes: 3 additions & 3 deletions tests/Unit/V1/FiltersBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function testBuildWithAllFields()

public function testAddInvalidIncludedCategory()
{
$this->expectException(\InvalidArgumentException::class);
$this->expectException(\UnexpectedValueException::class);
FiltersBuilder::construct()
->addIncludedCategoryFromString("not a category");
}
Expand Down Expand Up @@ -114,7 +114,7 @@ public function testAddIncludedFeatureFromString()

public function testAddInvalidExcludedCategory()
{
$this->expectException(\InvalidArgumentException::class);
$this->expectException(\UnexpectedValueException::class);
FiltersBuilder::construct()
->addExcludedCategoryFromString("not a category");
}
Expand Down Expand Up @@ -160,7 +160,7 @@ public function testAddDateRangeFromDateTimes()

public function testAddInvalidMediaType()
{
$this->expectException(\InvalidArgumentException::class);
$this->expectException(\UnexpectedValueException::class);
FiltersBuilder::construct()->setMediaTypeFromString("not a media type");
}

Expand Down

0 comments on commit b1b9437

Please sign in to comment.