mosharaf13 / fleet-searcher

Upload a CSV file containing keywords and view google search stats
1 stars 0 forks source link

[Question] Why hardcoding search URL in controller? #34

Closed olivierobert closed 1 year ago

olivierobert commented 1 year ago

Issue

https://github.com/mosharaf13/fleet-searcher/blob/dc70169cf85dd164c55b9b25b355c34390aa04f2/app/Http/Controllers/SearcherController.php#L39

The URL would make more sense to be defined in Searcher class. It seems out of place in the controller. Provided there would be multiple search providers, then each Search class should know to have all data to generate scraping URLs.

mosharaf13 commented 1 year ago

Yes, I makes more sense to put the URL in the Searcher class. I am planning to use a class variable inside this class to have the URL like below

class GoogleSearcher implements Searcher 
{ 
     protected WebDriver $driver; 
     protected string URL = ''https://www.google.com/search?hl=en&q=''; 
} 

It's a bit like hardcoding the URL. Which is sometimes discouraged.

Another way would be to read the value from .env and push it through the constructor by a config class.

I am assuming google won't change the search URL anytime soon. So, I am thinking about implementing the first solution. What's your thoughts on that?

olivierobert commented 1 year ago

In this case, declaring a static constant (or attribute as suggested) in the class would be sufficient as the value would indeed not change.