the function of a complex variable $\int\limits_{0}^{\pi}\frac{cos^2{\varphi}}{2-sin^2{\varphi}}d\varphi$
I think
$e^{i\varphi}=z$ $\to d\varphi=\frac{dz}{iz}$
$cos\varphi=\frac{z^2+1}{2z}$
$sin\varphi=\frac{z^2-1}{2iz}$
$\oint\limits_{|z|=1}^{}\frac{(z^2+1)^2}{iz(z^4+6z^2+1)}dz$
and then get 4 roots that are not good
and it is not clear how things
maybe I made the wrong conversion

You see, upper limit is only $\pi$. Do substitution after doubling of the argument:
$$\int\limits_0^{\pi}\dfrac{\cos^2 \phi}{2-\sin^2\phi}d\phi=\int\limits_0^{\pi}\dfrac{2\cos^2 \phi}{2+2\cos^2\phi}d\phi=\int\limits_0^{\pi}\dfrac{1+\cos 2\phi}{3+\cos2\phi}d\phi,$$
$$\quad e^{2i\phi}=z,\quad d\phi=\dfrac{dz}{2iz},\quad \cos 2\phi = \dfrac{z^2+1}{2z},\dots $$
