I guess the issues is here$data['percentage'] - it is the only obvious array access ; how do you know that $data is an array?
You can us the data_get helper method to mitigate these type of issue (where a key may not exist), and it wil handle the case where $data could be something unexpected, e.g.
This is an example, but might help... you attempt to get percentage from $data (which might be an array or object), but falls back to 'unknown' (or anything you choose) as a default.