Getting error Parse error: syntax error, unexpected ‘add_filter’ (T_STRING), expecting function (T_FUNCTION)

My guess would be you have just dropped filter into a class body in between the methods. That is invalid PHP and not going to work.

First you need to call it from where code makes sense, inside another class method or from outside a class.

Second you cannot hook methods by their name alone, you need to use proper callback with a name of the class. Examples would be [ __CLASS__, 'method_name' ] (static method) or [ $this, 'method_name' ] (non-static method in class instance).

And finally if you are new to PHP then spending some time with PHP manual is highly recommended, it will save you a lot of time in dealing with WordPress.